apm-agent-php icon indicating copy to clipboard operation
apm-agent-php copied to clipboard

TypeError: spl_object_id() expects parameter 1 to be object, resource given

Open GHostlyFOX opened this issue 2 years ago • 3 comments

Vercion v1.10.0

[Elastic APM PHP Tracer] 2023-09-14 11:59:15.065230+06:00 [PID: 1787] [TID: 1787] [ERROR]    [Interception] [InterceptionManager.php:117] [internalFuncCallPreHook] preHook has let a Throwable to escape {"throwable":{"type":"TypeError","value_as_string":"TypeError: spl_object_id() expects parameter 1 to be object, resource given in \/opt\/elastic\/apm-agent-php\/src\/ElasticApm\/Impl\/AutoInstrument\/CurlHandleWrappedTrait.php:103\nStack trace:\n#0 \/opt\/elastic\/apm-agent-php\/src\/ElasticApm\/Impl\/AutoInstrument\/CurlHandleWrappedTrait.php(103): spl_object_id(Resource id #358919)\n#1 \/opt\/elastic\/apm-agent-php\/src\/ElasticApm\/Impl\/AutoInstrument\/CurlHandleTracker.php(235): Elastic\\Apm\\Impl\\AutoInstrument\\CurlHandleWrapped->asInt()\n#2 \/opt\/elastic\/apm-agent-php\/src\/ElasticApm\/Impl\/AutoInstrument\/CurlHandleTracker.php(169): Elastic\\Apm\\Impl\\AutoInstrument\\CurlHandleTracker->assertCurlHandleInArgsMatches(Object(Elastic\\Apm\\Impl\\Util\\EnabledAssertProxy), 'curl_setopt_arr...', Array)\n#3 \/opt\/elastic\/apm-agent-php\/src\/ElasticApm\/Impl\/AutoInstrument\/CurlAutoInstrumentation.php(281): Elastic\\Apm\\Impl\\AutoInstrument\\CurlHandleTracker->preHook('curl_setopt_arr...', 3, Array)\n#4 \/opt\/elastic\/apm-agent-php\/src\/ElasticApm\/Impl\/AutoInstrument\/CurlAutoInstrumentation.php(115): Elastic\\Apm\\Impl\\AutoInstrument\\CurlAutoInstrumentation->createHandleTracker('curl_setopt_arr...', 3, Array)\n#5 \/opt\/elastic\/apm-agent-php\/src\/ElasticApm\/Impl\/AutoInstrument\/CurlAutoInstrumentation.php(101): Elastic\\Apm\\Impl\\AutoInstrument\\CurlAutoInstrumentation->preHook('curl_setopt_arr...', 3, Array)\n#6 \/opt\/elastic\/apm-agent-php\/src\/ElasticApm\/Impl\/AutoInstrument\/RegistrationContext.php(91): Elastic\\Apm\\Impl\\AutoInstrument\\CurlAutoInstrumentation->Elastic\\Apm\\Impl\\AutoInstrument\\{closure}(Array)\n#7 \/opt\/elastic\/apm-agent-php\/src\/ElasticApm\/Impl\/AutoInstrument\/InterceptionManager.php(115): Elastic\\Apm\\Impl\\AutoInstrument\\RegistrationContext->Elastic\\Apm\\Impl\\AutoInstrument\\{closure}(NULL, Array)\n#8 \/opt\/elastic\/apm-agent-php\/src\/ElasticApm\/Impl\/AutoInstrument\/PhpPartFacade.php(164): Elastic\\Apm\\Impl\\AutoInstrument\\InterceptionManager->internalFuncCallPreHook(2, NULL, Array)\n#9 [internal function]: Elastic\\Apm\\Impl\\AutoInstrument\\PhpPartFacade::internalFuncCallPreHook(2, NULL, Resource id #949, Array)

GHostlyFOX avatar Sep 14 '23 06:09 GHostlyFOX

Thank you for report @GHostlyFOX

Please provide more details What version of PHP you're using? Does the error appear after updating the Elastic agent?

Best regards, Pawel

intuibase avatar Sep 14 '23 08:09 intuibase

Agent version latest PHP version 7.4.33

GHostlyFOX avatar Sep 14 '23 09:09 GHostlyFOX

The code line in question is https://github.com/elastic/apm-agent-php/blob/7a7b0e0921d32679b1ef850585ca441624fc39ed/agent/php/ElasticApm/Impl/AutoInstrument/CurlHandleWrappedTrait.php#L103

According to https://www.php.net/manual/en/function.is-resource.php:

Note: is_resource() is not a strict type-checking method: it will return false if value is a resource variable that has been closed.

So it's possible that is_resource($this->curlHandle) returned false because $this->curlHandle is already closed.

SergeyKleyman avatar Feb 20 '24 09:02 SergeyKleyman