Skip to content

Commit 1a4c8c4

Browse files
committed
fix: review comments
1 parent 06e5233 commit 1a4c8c4

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

sdk/src/main/java/com/amazonaws/lambda/durable/DurableContext.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,25 @@ private DurableContext(
5050
durableConfig.getLoggerConfig().suppressReplayLogs());
5151
}
5252

53-
/** Creates a root context with the given contextId and registers the current thread. */
53+
/**
54+
* Creates a root context and registers the current thread for execution coordination.
55+
*
56+
* <p>The context itself always has a null contextId (making it a root context). The thread is registered with the
57+
* ExecutionManager using the default {@link #ROOT_CONTEXT} identifier.
58+
*
59+
* @param executionManager the execution manager
60+
* @param durableConfig the durable configuration
61+
* @param lambdaContext the Lambda context
62+
* @return a new root DurableContext
63+
*/
5464
static DurableContext createRootContext(
55-
ExecutionManager executionManager, DurableConfig durableConfig, Context lambdaContext, String contextId) {
65+
ExecutionManager executionManager, DurableConfig durableConfig, Context lambdaContext) {
5666
var ctx = new DurableContext(executionManager, durableConfig, lambdaContext, null);
57-
executionManager.registerActiveThread(contextId, ThreadType.CONTEXT);
58-
executionManager.setCurrentContext(contextId, ThreadType.CONTEXT);
67+
executionManager.registerActiveThread(ROOT_CONTEXT, ThreadType.CONTEXT);
68+
executionManager.setCurrentContext(ROOT_CONTEXT, ThreadType.CONTEXT);
5969
return ctx;
6070
}
6171

62-
/** Creates a root context with the default "Root" contextId and registers the current thread. */
63-
static DurableContext createRootContext(
64-
ExecutionManager executionManager, DurableConfig durableConfig, Context lambdaContext) {
65-
return createRootContext(executionManager, durableConfig, lambdaContext, ROOT_CONTEXT);
66-
}
67-
6872
/**
6973
* Creates a child context without registering the current thread. Thread registration is handled by
7074
* ChildContextOperation, which registers on the parent thread before the executor runs and sets the context on the

sdk/src/main/java/com/amazonaws/lambda/durable/operation/ChildContextOperation.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ private void executeChildContext() {
9999
// E.g., root child context "1", nested child context "1-2", deeply nested "1-2-1".
100100
var contextId = getOperationId();
101101

102-
// Register child context thread before executor runs (prevents suspension)
102+
// Thread registration is intentionally split across two threads:
103+
// 1. registerActiveThread on the PARENT thread — ensures the child is tracked before the
104+
// parent can deregister and trigger suspension (race prevention).
105+
// 2. setCurrentContext on the CHILD thread — sets the ThreadLocal so operations inside
106+
// the child context know which context they belong to.
107+
// registerActiveThread is idempotent (no-op if already registered).
103108
registerActiveThread(contextId, ThreadType.CONTEXT);
104109

105110
userExecutor.execute(() -> {

0 commit comments

Comments
 (0)