Bug #81673 [NEW]: Tracing JIT causing various errors (trait related?)

From: Date: Mon, 29 Nov 2021 22:02:48 +0000
Subject: Bug #81673 [NEW]: Tracing JIT causing various errors (trait related?)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238047@lists.php.net to get a copy of this message
From:             eric at ericstern dot com
Operating system: Alpine linux
PHP version:      8.0.13
Package:          JIT
Bug Type:         Bug
Bug description:Tracing JIT causing various errors (trait related?)

Description:
------------
When enabling the JIT in a production environment, I started getting
various errors in third-party libraries (guzzlehttp/psr7, though I doubt
it's relevant). After some poking and prodding, I was able to narrow it
down to the JIT running in tracing mode (via "on" or explicitly
"tracing"). Turning it back off or running it in "function" mode made
the errors disappear.

Notably, if I'm following my logs correctly, the first job seems to run
fine. It's only on the second+ job where the error comes up.

The errors that occurred included:

TypeError: GuzzleHttp\Psr7\Request::getBody(): Return value must be of
type Psr\Http\Message\StreamInterface, null returned in
/var/www/html/vendor/guzzlehttp/psr7/src/MessageTrait.php:127

Error: Cannot use object of type GuzzleHttp\Psr7\Uri as array in
/var/www/html/vendor/guzzlehttp/psr7/src/MessageTrait.php:161

(see linked file below)

In both cases, the errors make absolutely no sense for the given source
code, especially the latter. Which error I get seems basically random,
though the latter seems more common for any given worker. My gut tells
me the issue is somehow specific to traits, but I don't have any
practical way to verify that.

INI settings:
opcache.enable="1"
opcache.enable_cli="1"
(typical opcache prod values, preloading is enabled)
opcache.jit="on"
opcache.jit_buffer_size="128M"

Test script:
---------------
https://github.com/Firehed/php-jit-tracing-error
- this doesn't actually
reproduce the issue (yet), but it shows the approximate code structure
where it occurs.

The surrounding infrastructure/code in prod is fairly long and complex,
so I'm not sure how much needs to get added in to reproduce the issue.
But it's a run loop for an async job worker which performs a network
request and then parses and stores the results in a database. Nothing
too special. The code in question has been live for months without ever
having an issue.

Errors originate in this file:

https://github.com/guzzle/psr7/blob/2.1.0/src/MessageTrait.php

Expected result:
----------------
No errors

Actual result:
--------------
One backtrace:

TypeError: GuzzleHttp\Psr7\Request::getBody(): Return value must be of
type Psr\Http\Message\StreamInterface, null returned in
/var/www/html/vendor/guzzlehttp/psr7/src/MessageTrait.php:127
Stack trace:
#0 /var/www/html/vendor/guzzlehttp/psr7/src/Utils.php(222):
GuzzleHttp\Psr7\Request->getBody()
#1 /var/www/html/vendor/guzzlehttp/guzzle/src/Client.php(440):
GuzzleHttp\Psr7\Utils::modifyRequest(Object(GuzzleHttp\Psr7\Request),
Array)
#2 /var/www/html/vendor/guzzlehttp/guzzle/src/Client.php(326):
GuzzleHttp\Client->applyOptions(Object(GuzzleHttp\Psr7\Request), Array)
#3 /var/www/html/vendor/guzzlehttp/guzzle/src/Client.php(107):
GuzzleHttp\Client->transfer(Object(GuzzleHttp\Psr7\Request), Array)
#4 /var/www/html/vendor/guzzlehttp/guzzle/src/Client.php(123):
GuzzleHttp\Client->sendAsync(Object(GuzzleHttp\Psr7\Request), Array)
#5 /var/www/html/src/Worker/FetchStoreData.php(241):
GuzzleHttp\Client->send(Object(GuzzleHttp\Psr7\Request), Array)
#6 /var/www/html/src/Console/Worker/Run.php(213):
Slant\Normalizer\Worker\FetchStoreData->doJob(Array)
#7 [internal function]:
Slant\Normalizer\Console\Worker\Run->Slant\Normalizer\Console\Worker\{closure}(Object(Kicken\Gearman\Job\WorkerJob))
#8 /var/www/html/vendor/kicken/gearman-php/src/Worker.php(194):
call_user_func(Object(Closure), Object(Kicken\Gearman\Job\WorkerJob))
#9 /var/www/html/vendor/kicken/gearman-php/src/Worker.php(177):
Kicken\Gearman\Worker->processJob(Object(Kicken\Gearman\Protocol\Packet))
#10 /var/www/html/vendor/kicken/gearman-php/src/Worker.php(116):
Kicken\Gearman\Worker->processPacket(Object(Kicken\Gearman\Protocol\Packet))
#11 /var/www/html/src/Console/Worker/Run.php(145):
Kicken\Gearman\Worker->workOnce()
#12 /var/www/html/vendor/symfony/console/Command/Command.php(299):
Slant\Normalizer\Console\Worker\Run->execute(Object(Symfony\Component\Console\Input\ArgvInput),
Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/html/vendor/symfony/console/Application.php(978):
Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput),
Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /var/www/html/vendor/symfony/console/Application.php(295):
Symfony\Component\Console\Application->doRunCommand(Object(Slant\Normalizer\Console\Worker\Run),
Object(Symfony\Component\Console\Input\ArgvInput),
Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/html/vendor/symfony/console/Application.php(167):
Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput),
Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/html/bin/app(63):
Symfony\Component\Console\Application->run()
#17 {main}

-- 
Edit bug report at https://bugs.php.net/bug.php?id=81673&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=81673&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=81673&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=81673&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=81673&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=81673&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=81673&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=81673&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=81673&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=81673&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=81673&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81673&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=81673&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=81673&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=81673&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=81673&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=81673&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=81673&r=mysqlcfg


Thread (15 messages)

« previous php.bugs (#238047) next »