ecotone-dev icon indicating copy to clipboard operation
ecotone-dev copied to clipboard

Unexpected call to Scope::detach() for scope #XXXX, scope successfully detached but another scope should have been detached first

Open lifinsky opened this issue 11 months ago • 8 comments

Ecotone version(s) affected: latest

Description
Error thrown while running command "ecotone:run db". Message: "User Notice: Scope: unexpected call to Scope::detach() for scope #11818, scope successfully detached but another scope should have been detached first"

Context

ErrorException: User Notice: Scope: unexpected call to Scope::detach() for scope #11818, scope successfully detached but another scope should have been detached first
#47 /vendor/open-telemetry/context/DebugScope.php(55): OpenTelemetry\Context\DebugScope::detach
#46 /vendor/ecotone/open-telemetry/src/TracerInterceptor.php(52): Ecotone\OpenTelemetry\TracerInterceptor::traceAsynchronousEndpoint
#45 /vendor/ecotone/ecotone/src/Messaging/Handler/Processor/MethodInvoker/AroundMethodInvocation.php(67): Ecotone\Messaging\Handler\Processor\MethodInvoker\AroundMethodInvocation::proceed
#44 /vendor/ecotone/ecotone/src/Messaging/Handler/Processor/MethodInvoker/AroundMessageProcessor.php(33): Ecotone\Messaging\Handler\Processor\MethodInvoker\AroundMessageProcessor::process
#43 /vendor/ecotone/ecotone/src/Messaging/Handler/Processor/ChainedMessageProcessor.php(24): Ecotone\Messaging\Handler\Processor\ChainedMessageProcessor::process
#42 /vendor/ecotone/ecotone/src/Messaging/Handler/Gateway/Gateway.php(78): Ecotone\Messaging\Handler\Gateway\Gateway::execute
#41 /vendor/ecotone/ecotone/src/Messaging/Endpoint/PollingConsumer/InterceptedGateway.php(26): Ecotone\Messaging\Endpoint\PollingConsumer\InterceptedGateway::execute
#40 /vendor/ecotone/ecotone/src/Messaging/Endpoint/PollingConsumer/PollToGatewayTaskExecutor.php(37): Ecotone\Messaging\Endpoint\PollingConsumer\PollToGatewayTaskExecutor::execute
#39 /vendor/ecotone/ecotone/src/Messaging/Scheduling/SyncTaskScheduler.php(43): Ecotone\Messaging\Scheduling\SyncTaskScheduler::schedule
#38 /vendor/ecotone/ecotone/src/Messaging/Endpoint/PollingConsumer/ScheduledTaskConsumer.php(31): Ecotone\Messaging\Endpoint\PollingConsumer\ScheduledTaskConsumer::run
#37 /vendor/ecotone/ecotone/src/Messaging/Endpoint/PollingConsumer/InterceptedConsumer.php(52): Ecotone\Messaging\Endpoint\PollingConsumer\InterceptedConsumer::run
#36 /vendor/ecotone/ecotone/src/Messaging/Endpoint/PollingConsumer/InterceptedConsumerRunner.php(35): Ecotone\Messaging\Endpoint\PollingConsumer\InterceptedConsumerRunner::runEndpointWithExecutionPollingMetadata
#35 /vendor/ecotone/ecotone/src/Messaging/Config/MessagingSystemContainer.php(102): Ecotone\Messaging\Config\MessagingSystemContainer::run
#34 /vendor/ecotone/ecotone/src/Messaging/Config/Annotation/ModuleConfiguration/MessagingCommands/MessagingBaseCommand.php(43): Ecotone\Messaging\Config\Annotation\ModuleConfiguration\MessagingCommands\MessagingBaseCommand::runAsynchronousEndpointCommand
#33 /vendor/ecotone/ecotone/src/Messaging/Handler/Processor/MethodInvoker/MethodInvoker.php(38): Ecotone\Messaging\Handler\Processor\MethodInvoker\MethodInvoker::execute
#32 /vendor/ecotone/ecotone/src/Messaging/Handler/Processor/MethodInvokerProcessor.php(25): Ecotone\Messaging\Handler\Processor\MethodInvokerProcessor::process
#31 /vendor/ecotone/ecotone/src/Messaging/Handler/RequestReplyProducer.php(28): Ecotone\Messaging\Handler\RequestReplyProducer::handle
#30 /vendor/ecotone/ecotone/src/Messaging/Channel/DirectChannel.php(39): Ecotone\Messaging\Channel\DirectChannel::send
#29 /vendor/ecotone/ecotone/src/Messaging/Handler/Router/Router.php(59): Ecotone\Messaging\Handler\Router\Router::handle
#28 /vendor/ecotone/ecotone/src/Messaging/Channel/DirectChannel.php(39): Ecotone\Messaging\Channel\DirectChannel::send
#27 /vendor/ecotone/ecotone/src/Messaging/Handler/Gateway/GatewayInternalProcessor.php(63): Ecotone\Messaging\Handler\Gateway\GatewayInternalProcessor::process
#26 /vendor/ecotone/ecotone/src/Messaging/Handler/Processor/MethodInvoker/AroundMethodInvocation.php(57): Ecotone\Messaging\Handler\Processor\MethodInvoker\AroundMethodInvocation::proceed
#25 /vendor/ecotone/ecotone/src/Modelling/MessageHandling/MetadataPropagator/MessageHeadersPropagatorInterceptor.php(35): Ecotone\Modelling\MessageHandling\MetadataPropagator\MessageHeadersPropagatorInterceptor::storeHeaders
#24 /vendor/ecotone/ecotone/src/Messaging/Handler/Processor/MethodInvoker/AroundMethodInvocation.php(67): Ecotone\Messaging\Handler\Processor\MethodInvoker\AroundMethodInvocation::proceed
#23 /vendor/ecotone/ecotone/src/Messaging/Handler/Processor/MethodInvoker/AroundMessageProcessor.php(33): Ecotone\Messaging\Handler\Processor\MethodInvoker\AroundMessageProcessor::process
#22 /vendor/ecotone/ecotone/src/Messaging/Handler/Processor/ChainedMessageProcessor.php(24): Ecotone\Messaging\Handler\Processor\ChainedMessageProcessor::process
#21 /vendor/ecotone/ecotone/src/Messaging/Handler/Gateway/Gateway.php(78): Ecotone\Messaging\Handler\Gateway\Gateway::execute
#20 /var/cache/dev/ecotone/Ecotone_Messaging_Gateway_MessagingEntrypointWithHeadersPropagation.php(23): Ecotone\__Proxy__\Ecotone_Messaging_Gateway_MessagingEntrypointWithHeadersPropagation::sendWithHeaders
#19 /vendor/ecotone/ecotone/src/Messaging/Config/ConsoleCommandRunner.php(57): Ecotone\Messaging\Config\ConsoleCommandRunner::run
#18 /vendor/ecotone/ecotone/src/Messaging/Config/MessagingSystemContainer.php(57): Ecotone\Messaging\Config\MessagingSystemContainer::runConsoleCommand
#17 /vendor/ecotone/ecotone/src/Messaging/Config/Annotation/ModuleConfiguration/MessagingCommands/MessagingBaseCommand.php(17): Ecotone\Messaging\Config\Annotation\ModuleConfiguration\MessagingCommands\MessagingBaseCommand::executeConsoleCommand
#16 /vendor/ecotone/ecotone/src/Messaging/Handler/Processor/MethodInvoker/MethodInvoker.php(38): Ecotone\Messaging\Handler\Processor\MethodInvoker\MethodInvoker::execute
#15 /vendor/ecotone/ecotone/src/Messaging/Handler/Processor/MethodInvokerProcessor.php(25): Ecotone\Messaging\Handler\Processor\MethodInvokerProcessor::process
#14 /vendor/ecotone/ecotone/src/Messaging/Handler/RequestReplyProducer.php(28): Ecotone\Messaging\Handler\RequestReplyProducer::handle
#13 /vendor/ecotone/ecotone/src/Messaging/Channel/DirectChannel.php(39): Ecotone\Messaging\Channel\DirectChannel::send
#12 /vendor/ecotone/ecotone/src/Messaging/Handler/Gateway/GatewayInternalProcessor.php(63): Ecotone\Messaging\Handler\Gateway\GatewayInternalProcessor::process
#11 /vendor/ecotone/ecotone/src/Messaging/Handler/Gateway/Gateway.php(78): Ecotone\Messaging\Handler\Gateway\Gateway::execute
#10 /var/cache/dev/ecotone/Ecotone_Messaging_Gateway_ConsoleCommandRunner.php(18): Ecotone\__Proxy__\Ecotone_Messaging_Gateway_ConsoleCommandRunner::execute
#9 /vendor/ecotone/symfony-bundle/DependencyInjection/MessagingEntrypointCommand.php(63): Ecotone\SymfonyBundle\DependencyInjection\MessagingEntrypointCommand::execute
#8 /vendor/symfony/console/Command/Command.php(279): Symfony\Component\Console\Command\Command::run
#7 /vendor/symfony/console/Application.php(1049): Symfony\Component\Console\Application::doRunCommand
#6 /vendor/symfony/framework-bundle/Console/Application.php(125): Symfony\Bundle\FrameworkBundle\Console\Application::doRunCommand
#5 /vendor/symfony/console/Application.php(318): Symfony\Component\Console\Application::doRun
#4 /vendor/symfony/framework-bundle/Console/Application.php(79): Symfony\Bundle\FrameworkBundle\Console\Application::doRun
#3 /vendor/symfony/console/Application.php(169): Symfony\Component\Console\Application::run
#2 /vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php(49): Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner::run
#1 /vendor/autoload_runtime.php(29): require_once
#0 /bin/console(13): null

lifinsky avatar Dec 09 '24 10:12 lifinsky

@dgafka maybe we should use OTEL_PHP_DEBUG_SCOPES_DISABLED=true?

lifinsky avatar Dec 09 '24 11:12 lifinsky

TracerInterceptor

} catch (Throwable $exception) {
            $scope->detach();

            throw $exception;
        }

Maybe we should add try catch for $scope->detach(); since otherwise we cannot see the original exception

lifinsky avatar Dec 09 '24 12:12 lifinsky

} finally {
            $scope->detach();
        }

Maybe it also be better instead of 2 code blocks with detach method call

lifinsky avatar Dec 09 '24 13:12 lifinsky

Can you provide a failure test case for this?

dgafka avatar Feb 01 '25 15:02 dgafka

@dgafka At this point we have completely abandoned OpenTelemetry

lifinsky avatar Feb 01 '25 16:02 lifinsky

@lifinsky what do you use instead, and was this bug only the cause to abandon that?

dgafka avatar Feb 01 '25 18:02 dgafka

@dgafka At the moment, only Sentry. I would like to improve OpenTelemetry specifically in Ecotone and in general for Symfony logging (for example http routes), Doctrine and DBAL SQL queries, projection update execution, information on retries especially with a delay or getting into a dead letter. Probably, with better basic functionality, we could already add logging of http calls at the application level.

lifinsky avatar Feb 01 '25 20:02 lifinsky

I might give this package some more time for stability https://github.com/FriendsOfOpenTelemetry/opentelemetry-bundle

lifinsky avatar Feb 01 '25 23:02 lifinsky