{"record":{"id":"3206be156703e9e9","repo":"pinpoint-apm/pinpoint","slug":"duplicated-scope","errorCode":null,"errorMessage":"Duplicated {} scope={}","messagePattern":"Duplicated (.+?) scope=(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncScopeUtils.java","lineNumber":19,"sourceCode":"package com.navercorp.pinpoint.profiler.context;\n\nimport com.navercorp.pinpoint.bootstrap.context.Trace;\nimport com.navercorp.pinpoint.bootstrap.context.scope.TraceScope;\nimport org.apache.logging.log4j.LogManager;\nimport org.apache.logging.log4j.Logger;\n\npublic final class AsyncScopeUtils {\n    private static final Logger logger = LogManager.getLogger(AsyncScopeUtils.class);\n\n    private AsyncScopeUtils() {\n    }\n\n    public static boolean nested(Trace trace, String scopeName) {\n        // add async scope.\n        final TraceScope oldScope = trace.addScope(scopeName);\n        if (oldScope != null) {\n            if (logger.isWarnEnabled()) {\n                logger.warn(\"Duplicated {} scope={}\", trace.getClass().getSimpleName(), oldScope.getName());\n            }\n            // delete corrupted trace.\n//            deleteAsyncTrace(trace);\n            return true;\n        } else {\n            if (logger.isDebugEnabled()) {\n                logger.debug(\"start {} scope\", trace.getClass().getSimpleName());\n            }\n        }\n        return false;\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/pinpoint-apm/pinpoint/blob/744c3d3075e595656abb1ae331ad2c0e4c9eb996/agent-module/profiler/src/main/java/com/navercorp/pinpoint/profiler/context/AsyncScopeUtils.java#L1-L32","documentation":"WARN from AsyncScopeUtils.nested() when trace.addScope(scopeName) returns a non-null old scope, meaning an async scope with the same name already exists on this trace — the async trace block was entered re-entrantly or the scope was leaked by a previous unmatched begin/end. The code treats this as nesting and returns true so the caller can skip re-initialization; a commented-out deleteAsyncTrace indicates the old corrupted-trace cleanup is disabled, so the trace may carry stale state.","triggerScenarios":"Entering the same async scope twice on one trace: e.g. calling the async trace begin API twice without a matching end, or async callbacks sharing a single Trace object concurrently.","commonSituations":"Async instrumentation (CompletableFuture/executor plugins) where a callback is executed twice or a span event's traceBlockEnd is missed; custom plugins reusing one scope name per trace.","solutions":["Ensure every async trace block begin has exactly one matching end on the same trace.","Use a unique scope name per logical async unit instead of a shared constant across re-entrant calls.","Do not reuse a single Trace across concurrent async continuations; each continuation should get its own async trace.","If you see this repeatedly, check the installed plugin versions for known double-entry bugs and upgrade the agent."],"exampleFix":"// before\nAsyncScopeUtils.nested(trace, \"MY_ASYNC\"); // called again for same trace\n\n// after\nif (AsyncScopeUtils.nested(trace, \"MY_ASYNC\")) {\n    return; // skip duplicate scope entry\n}","handlingStrategy":"validation","validationCode":"// before entering an async scope, ensure it is not already active\nfinal TraceScope scope = trace.getScope(scopeName);\nif (scope != null) {\n    // scope already exists; skip addScope / nested entry\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair every async scope begin with exactly one end on the same Trace.","Use distinct scope names per async unit to avoid re-entrant collisions.","Never share one Trace object across concurrent async tasks."],"tags":["async","trace-scope","call-stack","instrumentation"],"backgroundTag":"internal-invariant-violation","analyzedSha":"744c3d3075e595656abb1ae331ad2c0e4c9eb996","analyzedAt":"2026-09-07T18:48:45.289Z","contentChangedAt":"2026-09-07T18:48:45.289Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}