Skip to content

fix: only cancel the context if the run is still processing #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ func (r *Run) Close() error {
return fmt.Errorf("run not started")
}

r.cancel(errAbortRun)
if !r.lock.TryLock() {
// If we can't get the lock, then the run is still running. Abort it.
r.cancel(errAbortRun)
}
if r.wait == nil {
return nil
}
Expand Down Expand Up @@ -285,10 +288,10 @@ func (r *Run) request(ctx context.Context, payload any) (err error) {
)
defer func() {
resp.Body.Close()
close(r.events)
cancel(r.err)
r.wait()
r.lock.Unlock()
close(r.events)
}()

r.callsLock.Lock()
Expand Down
Loading