chimit
3 months ago
382
3
Servers

502 Bad Gateway on firstOrCreate

Posted 3 months ago by chimit

I made a trivial code change in my project and PHP 7.3 starts crashing after it.

AuthServiceProvider.php

Before:

            $user = User::whereUid($token_payload->user_id)->first();

            if ($user === null) {
                $user = User::create([
                    'uid' => $token_payload->user_id,
                    'email' => $token_payload->email ?? null,
                ]);
            }

After:

            $user = User::firstOrCreate([
                'uid' => $token_payload->user_id
            ], [
                'email' => $token_payload->email ?? null,
            ]);

After a couple of minutes after pulling this commit PHP crashes and I get "502 Bad Gateway" from nginx.

MySQL requests generated by these two pieces of code are the same.

There is nothing in Laravel or nginx logs.

PHP 7.3 logs:

[21-Jul-2020 03:57:10] NOTICE: Reloading in progress ...
[21-Jul-2020 03:57:10] NOTICE: reloading: execvp("/usr/sbin/php-fpm7.3", {"/usr/sbin/php-fpm7.3", "--nodaemonize", "--fpm-config", "/etc/php/7.3/fpm/php-fpm.conf"})
[21-Jul-2020 03:57:10] NOTICE: using inherited socket fd=7, "/run/php/php7.3-fpm.sock"
[21-Jul-2020 03:57:10] NOTICE: using inherited socket fd=7, "/run/php/php7.3-fpm.sock"
[21-Jul-2020 03:57:10] NOTICE: fpm is running, pid 26088
[21-Jul-2020 03:57:10] NOTICE: ready to handle connections
[21-Jul-2020 03:57:10] NOTICE: systemd monitor interval set to 10000ms
[21-Jul-2020 04:02:23] WARNING: [pool www] server reached pm.max_children setting (5), consider raising it

If I revert this commit and restart php-fpm everything works smoothly again.

P.S. It's a Laravel Forge server.

Please sign in or create an account to participate in this conversation.