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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions datasets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
)

func TestDatasets(t *testing.T) {
t.Skipf("Changes have been made to the dataset API, this test needs to be updated")

workspaceID, err := g.CreateWorkspace(context.Background(), "directory")
require.NoError(t, err)

Expand Down
9 changes: 6 additions & 3 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 @@ -257,7 +260,7 @@ func (r *Run) request(ctx context.Context, payload any) (err error) {
r.responseCode = resp.StatusCode
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusBadRequest {
r.state = Error
r.err = fmt.Errorf("run encountered an error")
r.err = fmt.Errorf("run encountered an error: status code %d", resp.StatusCode)
} else {
r.state = Running
}
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