Skip to content

Commit 282df9a

Browse files
committed
Fix: fix close bug when run is aborted
Signed-off-by: Daishan Peng <[email protected]>
1 parent 31ce029 commit 282df9a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: pkg/sdkserver/routes.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,13 @@ func (s *server) execHandler(w http.ResponseWriter, r *http.Request) {
176176

177177
defer func() {
178178
s.runningLock.Lock()
179+
// Need to check if the cancel is still in map. In case when user abort, the channel will be deleted from map and closed already, and closing it again will panic
180+
_, ok := s.running[runID]
181+
if ok {
182+
close(cancel)
183+
}
179184
delete(s.running, runID)
180185
s.runningLock.Unlock()
181-
close(cancel)
182186
}()
183187

184188
// Ensure chat state is not empty.

0 commit comments

Comments
 (0)