feat(executor): add upstream disconnect handling for Codex WebSocket sessions
- Introduced `UpstreamDisconnectChan` for Codex WebSocket sessions to notify downstream connections of upstream disconnections. - Implemented `notifyUpstreamDisconnect` to signal errors and close channels on disconnect events. - Added integration tests to validate WebSocket session behavior on upstream disconnect. - Updated OpenAI WebSocket response handlers to properly close connections upon upstream disconnect notifications.
This commit is contained in:
@@ -56,6 +56,31 @@ func (h *OpenAIResponsesAPIHandler) ResponsesWebsocket(c *gin.Context) {
|
||||
retainResponsesWebsocketToolCaches(downstreamSessionKey)
|
||||
clientIP := websocketClientAddress(c)
|
||||
log.Infof("responses websocket: client connected id=%s remote=%s", passthroughSessionID, clientIP)
|
||||
|
||||
wsDone := make(chan struct{})
|
||||
defer close(wsDone)
|
||||
|
||||
if h != nil && h.AuthManager != nil {
|
||||
if exec, ok := h.AuthManager.Executor("codex"); ok && exec != nil {
|
||||
type upstreamDisconnectSubscriber interface {
|
||||
UpstreamDisconnectChan(sessionID string) <-chan error
|
||||
}
|
||||
if subscriber, ok := exec.(upstreamDisconnectSubscriber); ok && subscriber != nil {
|
||||
disconnectCh := subscriber.UpstreamDisconnectChan(passthroughSessionID)
|
||||
if disconnectCh != nil {
|
||||
go func() {
|
||||
select {
|
||||
case <-wsDone:
|
||||
return
|
||||
case <-disconnectCh:
|
||||
_ = conn.Close()
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var wsTerminateErr error
|
||||
var wsTimelineLog strings.Builder
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user