DataDog / dd-trace-php

Datadog PHP Clients
https://docs.datadoghq.com/tracing/setup/php
Other
497 stars 155 forks source link

[BUG] PHP Fatal error: Invalid opcode 137/1/0 & 137/8/0 #1911

Closed matthewnessworthy closed 1 year ago

matthewnessworthy commented 1 year ago

Bug description

PHP Fatal error:  Invalid opcode 137/1/0. in phar:///usr/local/bin/composer/vendor/composer/class-map-generator/src/PhpFileCleaner.php on line 168

and

PHP Fatal error:  Invalid opcode 137/8/0. in /var/www/app/vendor/phpseclib/phpseclib/phpseclib/Math/BigInteger/Engines/PHP.php on line 1320

PHP version

Output of php -v

PHP 8.1.11 (cli) (built: Sep 29 2022 22:29:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.11, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.11, Copyright (c), by Zend Technologies
    with ddtrace v0.84.0, Copyright Datadog, by Datadog
    with datadog-profiling v0.13.0, Copyright Datadog, by Datadog
    with ddappsec v0.6.0, Copyright Datadog, by Datadog

Tracer version

Output of php -r "echo phpversion('ddtrace').PHP_EOL;"

0.84.0

Installed extensions

Output of php -m

[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
datadog-profiling
date
ddappsec
ddtrace
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
intl
json
libxml
mbstring
memcached
mongodb
msgpack
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache
datadog-profiling
ddappsec
ddtrace

OS info

PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
UBUNTU_CODENAME=jammy

Diagnostics and configuration

Output of phpinfo() (ddtrace >= 0.47.0)

ddtrace

Datadog PHP tracer extension
For help, check out the documentation at https://docs.datadoghq.com/tracing/languages/php/
(c) Datadog 2020

Datadog tracing support => disabled
Version => 0.84.0
DATADOG TRACER CONFIGURATION => {
    "date": "2023-02-07T14:29:59Z",
    "os_name": "Linux b971d2c1850c 5.10.0-21-cloud-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64",
    "os_version": "5.10.0-21-cloud-amd64",
    "version": "0.84.0",
    "lang": "php",
    "lang_version": "8.1.14",
    "env": null,
    "enabled": true,
    "service": null,
    "enabled_cli": false,
    "agent_url": "http:\/\/localhost:8126",
    "debug": false,
    "analytics_enabled": false,
    "sample_rate": 1,
    "sampling_rules": [],
    "tags": [],
    "service_mapping": [],
    "distributed_tracing_enabled": true,
    "priority_sampling_enabled": true,
    "dd_version": null,
    "architecture": "x86_64",
    "sapi": "cli",
    "datadog.trace.request_init_hook": "\/opt\/datadog\/dd-library\/0.84.0\/dd-trace-sources\/bridge\/dd_wrap_autoloader.php",
    "open_basedir_configured": false,
    "uri_fragment_regex": null,
    "uri_mapping_incoming": null,
    "uri_mapping_outgoing": null,
    "auto_flush_enabled": false,
    "generate_root_span": true,
    "http_client_split_by_domain": false,
    "measure_compile_time": true,
    "report_hostname_on_root_span": false,
    "traced_internal_functions": null,
    "auto_prepend_file_configured": false,
    "integrations_disabled": "default",
    "enabled_from_env": false,
    "opcache.file_cache": null,
    "agent_error": "Failed to connect to localhost port 8126 after 0 ms: Connection refused"
}

Directive => Local Value => Master Value
datadog.agent_host => no value => no value
datadog.autofinish_spans => Off => Off
datadog.cakephp_analytics_enabled => Off => Off
datadog.cakephp_analytics_sample_rate => 1 => 1
datadog.codeigniter_analytics_enabled => Off => Off
datadog.codeigniter_analytics_sample_rate => 1 => 1
datadog.curl_analytics_enabled => Off => Off
datadog.curl_analytics_sample_rate => 1 => 1
datadog.distributed_tracing => On => On
datadog.dogstatsd_port => 8125 => 8125
datadog.dogstatsd_url => no value => no value
datadog.elasticsearch_analytics_enabled => Off => Off
datadog.elasticsearch_analytics_sample_rate => 1 => 1
datadog.eloquent_analytics_enabled => Off => Off
datadog.eloquent_analytics_sample_rate => 1 => 1
datadog.env => no value => no value
datadog.guzzle_analytics_enabled => Off => Off
datadog.guzzle_analytics_sample_rate => 1 => 1
datadog.integrations_disabled => default => default
datadog.laravel_analytics_enabled => Off => Off
datadog.laravel_analytics_sample_rate => 1 => 1
datadog.log_backtrace => Off => Off
datadog.lumen_analytics_enabled => Off => Off
datadog.lumen_analytics_sample_rate => 1 => 1
datadog.memcached_analytics_enabled => Off => Off
datadog.memcached_analytics_sample_rate => 1 => 1
datadog.mongo_analytics_enabled => Off => Off
datadog.mongo_analytics_sample_rate => 1 => 1
datadog.mongodb_analytics_enabled => Off => Off
datadog.mongodb_analytics_sample_rate => 1 => 1
datadog.mysqli_analytics_enabled => Off => Off
datadog.mysqli_analytics_sample_rate => 1 => 1
datadog.nette_analytics_enabled => Off => Off
datadog.nette_analytics_sample_rate => 1 => 1
datadog.pcntl_analytics_enabled => Off => Off
datadog.pcntl_analytics_sample_rate => 1 => 1
datadog.pdo_analytics_enabled => Off => Off
datadog.pdo_analytics_sample_rate => 1 => 1
datadog.phpredis_analytics_enabled => Off => Off
datadog.phpredis_analytics_sample_rate => 1 => 1
datadog.predis_analytics_enabled => Off => Off
datadog.predis_analytics_sample_rate => 1 => 1
datadog.priority_sampling => On => On
datadog.propagation_style_extract => tracecontext,Datadog,B3,B3 single header => tracecontext,Datadog,B3,B3 single header
datadog.propagation_style_inject => tracecontext,Datadog => tracecontext,Datadog
datadog.roadrunner_analytics_enabled => Off => Off
datadog.roadrunner_analytics_sample_rate => 1 => 1
datadog.sampling_rate => 1 => 1
datadog.service => no value => no value
datadog.service_mapping => no value => no value
datadog.service_name => no value => no value
datadog.slim_analytics_enabled => Off => Off
datadog.slim_analytics_sample_rate => 1 => 1
datadog.span_sampling_rules => [] => []
datadog.span_sampling_rules_file => no value => no value
datadog.symfony_analytics_enabled => Off => Off
datadog.symfony_analytics_sample_rate => 1 => 1
datadog.tags => no value => no value
datadog.trace.128_bit_traceid_generation_enabled => Off => Off
datadog.trace.agent_attempt_retry_time_msec => 5000 => 5000
datadog.trace.agent_connect_timeout => 100 => 100
datadog.trace.agent_debug_verbose_curl => Off => Off
datadog.trace.agent_flush_after_n_requests => 10 => 10
datadog.trace.agent_flush_interval => 5000 => 5000
datadog.trace.agent_max_consecutive_failures => 3 => 3
datadog.trace.agent_max_payload_size => 52428800 => 52428800
datadog.trace.agent_port => 0 => 0
datadog.trace.agent_stack_backlog => 12 => 12
datadog.trace.agent_stack_initial_size => 131072 => 131072
datadog.trace.agent_timeout => 500 => 500
datadog.trace.agent_url => no value => no value
datadog.trace.analytics_enabled => Off => Off
datadog.trace.auto_flush_enabled => Off => Off
datadog.trace.beta_high_memory_pressure_percent => 80 => 80
datadog.trace.bgs_connect_timeout => 2000 => 2000
datadog.trace.bgs_timeout => 5000 => 5000
datadog.trace.cakephp_analytics_enabled => Off => Off
datadog.trace.cakephp_analytics_sample_rate => 1 => 1
datadog.trace.cakephp_enabled => On => On
datadog.trace.cli_enabled => Off => Off
datadog.trace.client_ip_enabled => Off => Off
datadog.trace.client_ip_header => no value => no value
datadog.trace.codeigniter_analytics_enabled => Off => Off
datadog.trace.codeigniter_analytics_sample_rate => 1 => 1
datadog.trace.codeigniter_enabled => On => On
datadog.trace.curl_analytics_enabled => Off => Off
datadog.trace.curl_analytics_sample_rate => 1 => 1
datadog.trace.curl_enabled => On => On
datadog.trace.db_client_split_by_instance => Off => Off
datadog.trace.debug => Off => Off
datadog.trace.debug_curl_output => Off => Off
datadog.trace.debug_prng_seed => -1 => -1
datadog.trace.elasticsearch_analytics_enabled => Off => Off
datadog.trace.elasticsearch_analytics_sample_rate => 1 => 1
datadog.trace.elasticsearch_enabled => On => On
datadog.trace.eloquent_analytics_enabled => Off => Off
datadog.trace.eloquent_analytics_sample_rate => 1 => 1
datadog.trace.eloquent_enabled => On => On
datadog.trace.enabled => Off => On
datadog.trace.forked_process => On => On
datadog.trace.generate_root_span => On => On
datadog.trace.global_tags => no value => no value
datadog.trace.guzzle_analytics_enabled => Off => Off
datadog.trace.guzzle_analytics_sample_rate => 1 => 1
datadog.trace.guzzle_enabled => On => On
datadog.trace.header_tags => no value => no value
datadog.trace.health_metrics_enabled => Off => Off
datadog.trace.health_metrics_heartbeat_sample_rate => 0.001 => 0.001
datadog.trace.http_client_split_by_domain => Off => Off
datadog.trace.http_url_query_param_allowed => * => *
datadog.trace.laravel_analytics_enabled => Off => Off
datadog.trace.laravel_analytics_sample_rate => 1 => 1
datadog.trace.laravel_enabled => On => On
datadog.trace.lumen_analytics_enabled => Off => Off
datadog.trace.lumen_analytics_sample_rate => 1 => 1
datadog.trace.lumen_enabled => On => On
datadog.trace.measure_compile_time => On => On
datadog.trace.memcached_analytics_enabled => Off => Off
datadog.trace.memcached_analytics_sample_rate => 1 => 1
datadog.trace.memcached_enabled => On => On
datadog.trace.memory_limit => no value => no value
datadog.trace.mongo_analytics_enabled => Off => Off
datadog.trace.mongo_analytics_sample_rate => 1 => 1
datadog.trace.mongo_enabled => On => On
datadog.trace.mongodb_analytics_enabled => Off => Off
datadog.trace.mongodb_analytics_sample_rate => 1 => 1
datadog.trace.mongodb_enabled => On => On
datadog.trace.mysqli_analytics_enabled => Off => Off
datadog.trace.mysqli_analytics_sample_rate => 1 => 1
datadog.trace.mysqli_enabled => On => On
datadog.trace.nette_analytics_enabled => Off => Off
datadog.trace.nette_analytics_sample_rate => 1 => 1
datadog.trace.nette_enabled => On => On
datadog.trace.obfuscation_query_string_regexp => (?i)(?:p(?:ass)?w(?:or)?d|pass(?:_?phrase)?|secret|(?:api_?|private_?|public_?|access_?|secret_?)key(?:_?id)?|token|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)(?:(?:\s|%20)*(?:=|%3D)[^&]+|(?:"|%22)(?:\s|%20)*(?::|%3A)(?:\s|%20)*(?:"|%22)(?:%2[^2]|%[^2]|[^"%])+(?:"|%22))|bearer(?:\s|%20)+[a-z0-9\._\-]|token(?::|%3A)[a-z0-9]{13}|gh[opsu]_[0-9a-zA-Z]{36}|ey[I-L](?:[\w=-]|%3D)+\.ey[I-L](?:[\w=-]|%3D)+(?:\.(?:[\w.+\/=-]|%3D|%2F|%2B)+)?|[\-]{5}BEGIN(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY[\-]{5}[^\-]+[\-]{5}END(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY|ssh-rsa(?:\s|%20)*(?:[a-z0-9\/\.+]|%2F|%5C|%2B){100,} => (?i)(?:p(?:ass)?w(?:or)?d|pass(?:_?phrase)?|secret|(?:api_?|private_?|public_?|access_?|secret_?)key(?:_?id)?|token|consumer_?(?:id|key|secret)|sign(?:ed|ature)?|auth(?:entication|orization)?)(?:(?:\s|%20)*(?:=|%3D)[^&]+|(?:"|%22)(?:\s|%20)*(?::|%3A)(?:\s|%20)*(?:"|%22)(?:%2[^2]|%[^2]|[^"%])+(?:"|%22))|bearer(?:\s|%20)+[a-z0-9\._\-]|token(?::|%3A)[a-z0-9]{13}|gh[opsu]_[0-9a-zA-Z]{36}|ey[I-L](?:[\w=-]|%3D)+\.ey[I-L](?:[\w=-]|%3D)+(?:\.(?:[\w.+\/=-]|%3D|%2F|%2B)+)?|[\-]{5}BEGIN(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY[\-]{5}[^\-]+[\-]{5}END(?:[a-z\s]|%20)+PRIVATE(?:\s|%20)KEY|ssh-rsa(?:\s|%20)*(?:[a-z0-9\/\.+]|%2F|%5C|%2B){100,}
datadog.trace.pcntl_analytics_enabled => Off => Off
datadog.trace.pcntl_analytics_sample_rate => 1 => 1
datadog.trace.pcntl_enabled => On => On
datadog.trace.pdo_analytics_enabled => Off => Off
datadog.trace.pdo_analytics_sample_rate => 1 => 1
datadog.trace.pdo_enabled => On => On
datadog.trace.phpredis_analytics_enabled => Off => Off
datadog.trace.phpredis_analytics_sample_rate => 1 => 1
datadog.trace.phpredis_enabled => On => On
datadog.trace.predis_analytics_enabled => Off => Off
datadog.trace.predis_analytics_sample_rate => 1 => 1
datadog.trace.predis_enabled => On => On
datadog.trace.propagate_service => Off => Off
datadog.trace.propagation_style => tracecontext,Datadog => tracecontext,Datadog
datadog.trace.propagation_style_extract => tracecontext,Datadog,B3,B3 single header => tracecontext,Datadog,B3,B3 single header
datadog.trace.propagation_style_inject => tracecontext,Datadog => tracecontext,Datadog
datadog.trace.rate_limit => 0 => 0
datadog.trace.redis_client_split_by_host => Off => Off
datadog.trace.report_hostname => Off => Off
datadog.trace.request_init_hook => /opt/datadog/dd-library/0.84.0/dd-trace-sources/bridge/dd_wrap_autoloader.php => /opt/datadog/dd-library/0.84.0/dd-trace-sources/bridge/dd_wrap_autoloader.php
datadog.trace.resource_uri_fragment_regex => no value => no value
datadog.trace.resource_uri_mapping_incoming => no value => no value
datadog.trace.resource_uri_mapping_outgoing => no value => no value
datadog.trace.resource_uri_query_param_allowed => no value => no value
datadog.trace.retain_thread_capabilities => Off => Off
datadog.trace.roadrunner_analytics_enabled => Off => Off
datadog.trace.roadrunner_analytics_sample_rate => 1 => 1
datadog.trace.roadrunner_enabled => On => On
datadog.trace.sample_rate => 1 => 1
datadog.trace.sampling_rules => [] => []
datadog.trace.shutdown_timeout => 5000 => 5000
datadog.trace.slim_analytics_enabled => Off => Off
datadog.trace.slim_analytics_sample_rate => 1 => 1
datadog.trace.slim_enabled => On => On
datadog.trace.spans_limit => 1000 => 1000
datadog.trace.startup_logs => On => On
datadog.trace.symfony_analytics_enabled => Off => Off
datadog.trace.symfony_analytics_sample_rate => 1 => 1
datadog.trace.symfony_enabled => On => On
datadog.trace.traced_internal_functions => no value => no value
datadog.trace.url_as_resource_names_enabled => On => On
datadog.trace.warn_legacy_dd_trace => On => On
datadog.trace.web_analytics_enabled => Off => Off
datadog.trace.web_analytics_sample_rate => 1 => 1
datadog.trace.web_enabled => On => On
datadog.trace.wordpress_analytics_enabled => Off => Off
datadog.trace.wordpress_analytics_sample_rate => 1 => 1
datadog.trace.wordpress_enabled => On => On
datadog.trace.x_datadog_tags_max_length => 512 => 512
datadog.trace.yii_analytics_enabled => Off => Off
datadog.trace.yii_analytics_sample_rate => 1 => 1
datadog.trace.yii_enabled => On => On
datadog.trace.zendframework_analytics_enabled => Off => Off
datadog.trace.zendframework_analytics_sample_rate => 1 => 1
datadog.trace.zendframework_enabled => On => On
datadog.version => no value => no value
datadog.web_analytics_enabled => Off => Off
datadog.web_analytics_sample_rate => 1 => 1
datadog.wordpress_analytics_enabled => Off => Off
datadog.wordpress_analytics_sample_rate => 1 => 1
datadog.yii_analytics_enabled => Off => Off
datadog.yii_analytics_sample_rate => 1 => 1
datadog.zendframework_analytics_enabled => Off => Off
datadog.zendframework_analytics_sample_rate => 1 => 1
ddtrace.cgroup_file => /proc/self/cgroup => /proc/self/cgroup
ddtrace.disable => Off => Off
ddtrace.request_init_hook => /opt/datadog/dd-library/0.84.0/dd-trace-sources/bridge/dd_wrap_autoloader.php => /opt/datadog/dd-library/0.84.0/dd-trace-sources/bridge/dd_wrap_autoloader.php

Upgrading info

dd-trace 0.82.0

bwoebi commented 1 year ago

Hey @matthewnessworthy,

I assume the fatal errors only happen with ddtrace loaded, but not without? Also, what version of phpseclib and the composer class map generator do you have? So that I can look at the exact code at the given line numbers.

It is weird to me to see that error pop up. Opcode 137 is ZEND_OP_DATA, an opcode which should never be executed. I wonder why this would happen; at least we are not directly interacting with opcodes having ZEND_OP_DATA.

I'd appreciate more information which could help me track this down, thanks!

matthewnessworthy commented 1 year ago

@bwoebi thanks for following up, the requested version info is below

I upgraded the PHP version from 8.1.11 to 8.1.15 and the problem went away, so for me at least, this is no longer an issue

phpseclib/phpseclib version from my composer.lock

        {
            "name": "phpseclib/phpseclib",
            "version": "3.0.18",
            "source": {
                "type": "git",
                "url": "https://github.com/phpseclib/phpseclib.git",
                "reference": "f28693d38ba21bb0d9f0c411ee5dae2b178201da"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/f28693d38ba21bb0d9f0c411ee5dae2b178201da",
                "reference": "f28693d38ba21bb0d9f0c411ee5dae2b178201da",
                "shasum": ""
            },

composer/class-map-generator version from my composer.lock

        {
            "name": "composer/class-map-generator",
            "version": "1.0.0",
            "source": {
                "type": "git",
                "url": "https://github.com/composer/class-map-generator.git",
                "reference": "1e1cb2b791facb2dfe32932a7718cf2571187513"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/composer/class-map-generator/zipball/1e1cb2b791facb2dfe32932a7718cf2571187513",
                "reference": "1e1cb2b791facb2dfe32932a7718cf2571187513",
                "shasum": ""
            },
bwoebi commented 1 year ago

Looking at the changelog for the lastest PHP 8.1 versions, I find https://github.com/php/php-src/commit/4d4a53beee2b815ccd9f2905efd4f7f177c18ec8. (A misoptimization of the opcode which fails for you.)

I suspect this is thus not a problem in ddtrace itself, and we can close this issue again @matthewnessworthy ?

Thanks for the quick reply!

matthewnessworthy commented 1 year ago

@bwoebi thanks, yes, we can go ahead and close this issue