Skip to content

Commit aab345f

Browse files
committed
Use RESOURCE_BUSY error code for session conflicts
Changes INTERNAL_ERROR (500) to RESOURCE_BUSY (409) for "session already exists" errors. This prevents noisy ERROR-level logs during wrangler dev hot reloads since the SDK only logs 5xx errors. Also improves the debug message to clarify state divergence.
1 parent 933cf84 commit aab345f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/sandbox-container/src/services/session-manager.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ export class SessionManager {
3232
success: false,
3333
error: {
3434
message: `Session '${options.id}' already exists`,
35-
code: ErrorCode.INTERNAL_ERROR,
35+
code: ErrorCode.RESOURCE_BUSY,
3636
details: {
37-
sessionId: options.id,
38-
originalError: 'Session already exists'
39-
} satisfies InternalErrorContext
37+
sessionId: options.id
38+
}
4039
}
4140
};
4241
}

packages/sandbox/src/sandbox.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,10 @@ export class Sandbox<Env = unknown> extends Container<Env> implements ISandbox {
10151015
} catch (error: unknown) {
10161016
// Session may already exist (e.g., after hot reload or concurrent request)
10171017
if (error instanceof Error && error.message.includes('already exists')) {
1018-
this.logger.debug('Reusing existing session', { sessionId });
1018+
this.logger.debug(
1019+
'Session exists in container but not in DO state, syncing',
1020+
{ sessionId }
1021+
);
10191022
this.defaultSession = sessionId;
10201023
await this.ctx.storage.put('defaultSession', sessionId);
10211024
} else {

0 commit comments

Comments
 (0)