Skip to content

Destroy background resources invalidated by Close or Reset - #48

Merged
jackc merged 1 commit into
jackc:masterfrom
bensynapse:fix-tryacquire-close
Oct 4, 2026
Merged

jackc merged 1 commit into
jackc:masterfrom
bensynapse:fix-tryacquire-close

Conversation

@bensynapse

Copy link
Copy Markdown
Contributor

I run Live Tennis API.

If Close runs while TryAcquire is constructing a resource, the constructor can put that resource into the closed pool. Close then waits forever for its destructor. A concurrent Reset can also leave a stale resource available for acquisition.

Check the closed state and reset generation before adding the completed resource to the idle pool. Destroy invalidated resources in the background and release their capacity.

The two new tests synchronize construction with closure and reset. They also check that Close waits for destruction and that acquisition after Reset creates a fresh resource. Both tests fail before the fix.

go test -v -race ./... passes on Go 1.19, 1.20 and 1.23.4. Both regressions pass 50 race runs. go build ./... and formatting pass.

go vet ./... reports an existing benchmark calling testing.B.Fatal from a goroutine. The same diagnostic occurs on untouched upstream.

Destroy resources completed by TryAcquire after Close or Reset.
Otherwise Close can wait forever and Reset can reuse a stale resource.
@jackc
jackc merged commit 5fbb0dd into jackc:master Oct 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants