logo

Debugging a Mystery 502 on Laravel Forge

No exception, no log entry, and it only happened in production

Joel Clermont
Joel Clermont
2026-07-09

I was developing a new feature for this site, and it was the first time I was using defer() in this code base.

Everything worked fine locally, tests passed. But on production, when I tried out this new feature, I was getting an HTTP 502 error.

Even weirder, nothing showed up in laravel.log or in Sentry. The only clue was in the nginx error log.

[error] 194365#194365: *290075 recv() failed (104: Connection reset by peer) while reading response header from upstream

After a little bit of frustration, the culprit turned out to be the Swoole PHP extension.

Confusing things, I never installed this extension, and I don't use it, but it was apparently installed by default on my Forge server, although nothing in the docs or the UI indicates this. I only found it by looking at the PHP extensions on the server.

The problem is that Swoole defines its own global defer() function, which conflicts with Laravel's global defer() helper. An extension's functions exist before any of your PHP code loads, so Laravel saw Swoole's version and quietly skipped registering its own.

So I was inadvertently calling Swoole's defer() function which blows up inside a normal PHP-FPM request. The worker just dies with a fatal error and a 255 exit code.

That's not an exception Laravel can catch or report, so nothing was logged, and nginx returned a 502.

The fix is one line at the top of the file, to qualify which defer function I want to use.

use function Illuminate\Support\defer;

To Laravel's credit, this very conflict is called out in the docs, but I glossed over it the first time because I didn't install Swoole on that server.

Here to help,

Joel

P.S. Weird production errors are a lot less painful when you can talk them over with fellow devs. Join our community.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice.