Skip to content

Tighten queue cancel - #1188

Merged
AlCutter merged 3 commits into
transparency-dev:mainfrom
AlCutter:tighten_queue_cancel
Sep 18, 2026
Merged

AlCutter merged 3 commits into
transparency-dev:mainfrom
AlCutter:tighten_queue_cancel

Conversation

@AlCutter

Copy link
Copy Markdown
Collaborator

This PR tightens up the queue semantics when it's being closed down.

This should help avoid any deadlocks or ambiguity around whether leaves sent via Add() were accepted or errored.

@AlCutter
AlCutter requested a review from roger2hk September 18, 2026 13:10
@AlCutter
AlCutter requested a review from a team as a code owner September 18, 2026 13:10
Comment thread storage/internal/queue.go Outdated
Comment on lines +72 to +73
// Ensure timer is stopped once ctx is done and we return.
defer timer.Stop()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This seems to be a no-op since Go 1.23.

https://go.dev/doc/go1.23#timer-changes

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you're right - I was worried about a spurious tick but we have to have come out of here for the defer to work anyway.

Removed!

Comment thread storage/internal/queue.go
Comment on lines 141 to +149
case q.inputs <- qi:
case <-ctx.Done():
return func() (tessera.Index, error) {
return tessera.Index{}, ctx.Err()
}
case <-q.queueCtx.Done():
return func() (tessera.Index, error) {
return tessera.Index{}, q.queueCtx.Err()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If q.queueCtx is cancelled but the batching goroutine is still active, it's still possible to get an entry into the shutting-down queue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true, but only if the batching goroutine is in <-q.inputs on L111 (inputs is not buffered), so either that's impossible because it already detected the ctx cancelled, or as soon as it processes the recv and goes around the loop it'll detect the cancelled context and call cancelItems().

Comment thread storage/internal/queue_test.go Outdated
{
name: "worker blocked in flush and batches full",
maxSize: 2,
numItems: 2 + 2 + 2 + 1, // 2 in doFlush (flushFunc below), 2 in batches chan, 2 blocked in flush() (on batches<-), 1 blocked in Add() (on inputs<-).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test here doesn't fail (not flaky) but it is not always the same as what it describes.

The a.Add on L202 may not finish adding the entry when cancel() on L212 is called.

addWg.Go(func() {
	futures[i] = q.Add(t.Context(), tessera.NewEntry(fmt.Appendf(nil, "item %d", i)))
})

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gnash, gnash. Ok should be better now.

@AlCutter
AlCutter force-pushed the tighten_queue_cancel branch from 1dfde7c to 5db83a6 Compare September 18, 2026 15:58
@AlCutter
AlCutter merged commit 592130c into transparency-dev:main Sep 18, 2026
19 of 20 checks passed
@AlCutter
AlCutter deleted the tighten_queue_cancel branch September 18, 2026 16:14
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