Skip to content

An open-source, faster Devin alternative

TypeScript

fix: prevent attaching to dying exec sessions by checking timer.Stop() return value

motatoes03b295bdcc8b
diff --git a/internal/agent/exec_session.go b/internal/agent/exec_session.go
index 00029a52..4a000442 100644
--- a/internal/agent/exec_session.go
+++ b/internal/agent/exec_session.go
@@ -190,13 +190,17 @@ func (s *Server) ExecSessionAttach(stream pb.SandboxAgent_ExecSessionAttachServe
return fmt.Errorf("exec session %s not found", sessionID)
}
- // Increment attached clients
+ // Increment attached clients — check if session is already dying
sess.mu.Lock()
- sess.attachedClients++
if sess.disconnectTimer != nil {
- sess.disconnectTimer.Stop()
+ if !sess.disconnectTimer.Stop() {
+ // Timer already fired — session is being torn down
+ sess.mu.Unlock()
+ return fmt.Errorf("exec session %s is shutting down", sessionID)
+ }
sess.disconnectTimer = nil
}
+ sess.attachedClients++
sess.mu.Unlock()
defer func() {