Skip to content

Commit a43a654

Browse files
committed
fix: only cancel the context if the run is still processing
Signed-off-by: Donnie Adams <[email protected]>
1 parent df4a8c9 commit a43a654

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

run.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ func (r *Run) Close() error {
135135
return fmt.Errorf("run not started")
136136
}
137137

138-
r.cancel(errAbortRun)
138+
if !r.lock.TryLock() {
139+
// If we can't get the lock, then the run is still running. Abort it.
140+
r.cancel(errAbortRun)
141+
}
139142
if r.wait == nil {
140143
return nil
141144
}
@@ -285,10 +288,10 @@ func (r *Run) request(ctx context.Context, payload any) (err error) {
285288
)
286289
defer func() {
287290
resp.Body.Close()
288-
close(r.events)
289291
cancel(r.err)
290292
r.wait()
291293
r.lock.Unlock()
294+
close(r.events)
292295
}()
293296

294297
r.callsLock.Lock()

0 commit comments

Comments
 (0)