Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: upstream prematurely closed connection error after updating PHP versions #254

Closed
WendellAdriel opened this issue Nov 24, 2023 · 12 comments

Comments

@WendellAdriel
Copy link

Operating system version

macOS Sonoma 14.1.1

System architecture

Intel (x86)

Herd Version

1.3.1 (Build 18)

PHP Version

PHP 8.2.13 and PHP 8.3.0

Bug description

After updating my PHP versions to PHP 8.2.13 and PHP 8.3.0 I started to get this error:

upstream prematurely closed connection while reading response header from upstream

The weird thing is that this is happening only with endpoints that access a PgSQL DB. The application uses two DBs, a MySQL one and a PgSQL one. All endpoints that are accessing the MySQL one only are working, but all endpoints that access the PgSQL DB are resulting in this:

image

And when I check the logs the error above and on the Relevant log output are being added to the log file.

I already did some research and tried some solutions that I saw happening with Valet. Tried to uninstall and install Herd and the issue wasn't fixed.

This started to happen today after I updated my PHP versions on Herd.

Steps to reproduce

I can't share the repository since it's private, but a simple Laravel app that accesses a PgSQL DB with a simple query should be enough to check this behaviour.

Relevant log output

2023/11/24 16:21:56 [error] 8783#11646759: *1 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET /v1/brands/4572/competitor-suite/explore/whitespace-opportunities?timeframe=2d HTTP/1.1", upstream: "fastcgi://unix:/Users/wendell_adriel/Library/Application Support/Herd/herd.sock:", host: "trackstreet.test"
@mpociot
Copy link
Member

mpociot commented Nov 24, 2023

Hm is this related to laravel/valet#1433 ?

@WendellAdriel
Copy link
Author

I tried some solutions on this, but it didn't work.

I tried adding some fastcgi params like: laravel/valet#1433 (comment)

I also tried adding this: laravel/valet#1433 (comment) to the ~/Library/Application\ Support/Herd/config/fpm/8.2-fpm.conf but it didn't work as well.

Then I removed Herd completely from my computer and installed it again, the issue was still happening. Tried the solutions above again and the issue is still happening. IDK what to try anymore.

@crazywhalecc
Copy link

It seems that this problem cannot be reproduced in the existing running environment. I used the following steps:

  1. Install Herd and download PHP 8.3.0
  2. Connect to the database and install it using Homebrew: brew install postgresql
  3. Create an account and connect
  4. Use Herd to quickly create a Laravel project and insert var_dump(\Illuminate\Support\Facades\DB::select('SELECT 1,2,3,4,5')); into the homepage
  5. Successfully display query results

I first tried the above steps on Ventura and then on a clean Sonoma virtual machine, but the problem did not occur. Did I miss something?

@redpark2
Copy link

Exact same problem here.

When a Postgres connection is made, the Nginx upstream error triggers.
Also happens with PHP 8.3

All was working perfectly before upgrading to PHP 8.2.13.
Have uninstalled and reinstalled Herd twice...

Herd 1.3.1, PHP 8.2.13 or 8.3
macOS Sonoma 14.1.1
M1 architecture

@emredipi
Copy link

I am having same issue on PHP 8.2.13. I have debugged it and PHP PDO class causes the error with only Postgres.

Herd 1.3.1, PHP 8.2.13 or 8.3
macOS Sonoma 14.0
Intel i7

Is it possible to send rollback update until php fixes the issue? @mpociot

@Ewoutvans
Copy link

I was also having the same issue with connection to PostgreSQL databases

Herd: Version 1.3.1 (Build 18)
PHP 8.2.13
macOS Sonoma 14.1.1

I've done some testing and found if postgres has SSL mode on, the 502 Bad Gateway happens.
When disabling the SSL mode everything works as expected.
As @crazywhalecc pointed out with brew install postgresql it seems to work for me, and that's because ssl = off by default in homebrew. I'm however using a postgres server installed by forge where ssl is on.

@mpociot
Copy link
Member

mpociot commented Nov 25, 2023

Thanks for the SSL hint!
I just built new 8.2.13 versions that no longer have this issue.
It seems to be related to a specific OpenSSL version that gets used as a dependency.
The 8.3.0 version will be built as well.

@WendellAdriel
Copy link
Author

Thank you so much @mpociot!
Just tested it here and it's working now! 🔥

@askdkc
Copy link

askdkc commented Nov 29, 2023

@mpociot

Can you share how you build PHP for Herd by any chance? Configure options?

@thomas-shirley
Copy link

thomas-shirley commented Dec 13, 2023

It looks like this bug is not isolated to Herd. I'm running Homebrew php 8.3 and Postgres 14 standalone — with the same error.

@mpociot
Copy link
Member

mpociot commented Dec 13, 2023

@thomas-shirley Yeah, it's related to the specific openssl version that was used in combination with postgresql

@thomas-shirley
Copy link

Looks like this bug is being tracked in Homebrew core: Homebrew/homebrew-core#155651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants