Skip to content

Commit 94d48cf

Browse files
committed
feat(sse): add session ID handling for connections
1 parent d75f0d9 commit 94d48cf

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/transports/sse/server.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,25 @@ export class SSEServerTransport extends AbstractTransport {
119119
if (!isAuthenticated) return
120120
}
121121

122-
// Remove check for existing single _sseResponse
122+
// Check if a sessionId was provided in the request
123+
if (sessionId) {
124+
// If sessionId exists but is not in our connections map, it's invalid or inactive
125+
if (!this._connections.has(sessionId)) {
126+
logger.info(`Invalid or inactive session ID in GET request: ${sessionId}. Creating new connection.`);
127+
// Continue execution to create a new connection below
128+
} else {
129+
// If the connection exists and is still active, we could either:
130+
// 1. Return an error (409 Conflict) as a client shouldn't create duplicate connections
131+
// 2. Close the old connection and create a new one
132+
// 3. Keep the old connection and return its details
133+
134+
// Option 2: Close old connection and create new one
135+
logger.info(`Replacing existing connection for session ID: ${sessionId}`);
136+
this.cleanupConnection(sessionId);
137+
// Continue execution to create a new connection below
138+
}
139+
}
140+
123141
// Generate a unique ID for this specific connection
124142
const connectionId = randomUUID();
125143
this.setupSSEConnection(res, connectionId);

0 commit comments

Comments
 (0)