File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
engine/sdks/typescript/runner/src Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -573,6 +573,24 @@ export class Tunnel {
573573 return ;
574574 }
575575
576+ // Close existing WebSocket if one already exists for this request ID.
577+ // There should always be a close message sent before another open
578+ // message for the same message ID.
579+ //
580+ // This should never occur if all is functioning correctly, but this
581+ // prevents any edge case that would result in duplicate WebSockets for
582+ // the same request.
583+ const existingAdapter = this . #actorWebSockets. get ( requestIdStr ) ;
584+ if ( existingAdapter ) {
585+ this . log ?. warn ( {
586+ msg : "closing existing websocket for duplicate open event for the same request id" ,
587+ requestId : requestIdStr ,
588+ } ) ;
589+ // Close without sending a message through the tunnel since the server
590+ // already knows about the new connection
591+ existingAdapter . __closeWithoutCallback ( 1000 , "ws.duplicate_open" ) ;
592+ }
593+
576594 // Track this WebSocket for the actor
577595 if ( actor ) {
578596 actor . webSockets . add ( requestIdStr ) ;
You can’t perform that action at this time.
0 commit comments