open-telemetry / open-telemetry/opentelemetry-php
zend_mm_heap corrupted when using WithSpan hook
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 912
- Forks
- 232
- Avg merge
- 7d 16h
- Merged PRs (30d)
- 4
Description
Describe your environment
PHP 8.4.16 on Debian GNU/Linux 12 (bookworm) (from php:8.4-fpm-bookworm docker image)
php --ri opentelemetry
opentelemetry
opentelemetry hooks => enabled
extension version => 1.2.1
Directive => Local Value => Master Value
opentelemetry.conflicts => no value => no value
opentelemetry.validate_hook_functions => On => On
opentelemetry.allow_stack_extension => Off => Off
opentelemetry.attr_hooks_enabled => On => On
opentelemetry.display_warnings => Off => Off
opentelemetry.attr_pre_handler_function => OpenTelemetry\API\Instrumentation\WithSpanHandler::pre => OpenTelemetry\API\Instrumentation\WithSpanHandler::pre
opentelemetry.attr_post_handler_function => OpenTelemetry\API\Instrumentation\WithSpanHandler::post => OpenTelemetry\API\Instrumentation\WithSpanHandler::post
open-telemetry/api 1.7.1
open-telemetry/context 1.4.0
open-telemetry/exporter-otlp 1.3.3
open-telemetry/exporter-zipkin 1.1.1
open-telemetry/extension-propagator-b3 1.1.0
open-telemetry/gen-otlp-protobuf 1.8.0
open-telemetry/opentelemetry-auto-laravel 1.4.0
open-telemetry/opentelemetry-auto-psr18 1.1.1
open-telemetry/sdk 1.10.0
open-telemetry/sem-conv 1.37.0
Steps to reproduce
Define a function that uses the WithSpan hook and call it:
#[WithSpan(self::class . "::get_from_store")]
public function get_from_store(#[SpanAttribute] string $key): CacheObject {
...
}
What is the expected behavior?
Hook completes without crashing
What is the actual behavior?
PHP process crashes and does not complete some requests randomly with this error:
zend_mm_heap corrupted
This happens most requests but not all of them. It seems to be completely random which requests it happens on and which ones it doesn't. If I have more calls to WithSpan it seems to increase the frequency of occurrences. For example if I put the WithSpan attribute onto a function that gets called hundreds of times per request this crash happens every single time.
Sometimes (I can't figure out how to reproduce this one) I get this warning right before the above error message:
PHP Warning: [redacted]\AbstractRedisImplementation::get_from_store(): OpenTelemetry: post hook threw exception, class=[redacted]\AbstractRedisImplementation function=get_from_store message=Cannot assign [redacted]\CacheObject to property OpenTelemetry\Context\ContextStorageHead::$node of type ?OpenTelemetry\Context\ContextStorageNode in Unknown on line 0
Additional context
Add any other context about the problem here.
Tip: React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the crash with PHP 8.4.16, the WithSpan attribute, and repeated calls to the annotated method. Start by tracing the WithSpan pre and post hooks and the ContextStorageHead assignment mentioned in the warning. Done means the hook completes reliably without zend_mm_heap corruption or the post-hook type-assignment warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100