Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Fix panics in streaming completions handler#60474

Merged
cbart merged 2 commits into
mainfrom
cb/60439/fix-panics-in-streaming-response-handler
Feb 13, 2024
Merged

Fix panics in streaming completions handler#60474
cbart merged 2 commits into
mainfrom
cb/60439/fix-panics-in-streaming-response-handler

Conversation

@cbart

@cbart cbart commented Feb 13, 2024

Copy link
Copy Markdown
Contributor

Closes #60439

2 issues:

  • if no attribution search is triggered it can wait forever
  • if the attribution search returns a result while we stream other stuff, we might concurrently flush, causing panics (the panic message is not 100% the one from the ticket, but very close, and we were able to repro that, and not anymore after the fix)

Test plan

  • Manual check

Comment on lines +118 to +121
// If attribution never run, we're done.
a.attributionRun.Do(func() {
close(a.attributionFinished)
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TBH this fix feels sus. This looks like it is now possible to close a channel twice. How are you guarenteed that waitdone is only called once everything else is done?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To elaborate further why I think this is sus. We call runAttribution in a new goroutine, which means it is possible that you call WaitDone before we have tried writing to attributionFinished? I am gonna read the code even more now, but the internal invariants here are hard to keep track of since it feels so easy to misuse.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It should still be safe:

  • One routine enters attributionRun.Do (sync.Once)
  • Either:
    • This piece which just closes the channel
    • Or the attribution search (run async with go) - closes it at the end, but in that case once already triggered.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right! so the bit I missed was attributionRun was a sync.Once. That makes this all good. Thanks!

@cbart cbart merged commit 52dffbb into main Feb 13, 2024
@cbart cbart deleted the cb/60439/fix-panics-in-streaming-response-handler branch February 13, 2024 13:31
sourcegraph-release-bot pushed a commit that referenced this pull request Feb 13, 2024
* Fix panics in streaming completions handler

* FMT

(cherry picked from commit 52dffbb)
keegancsmith pushed a commit that referenced this pull request Feb 13, 2024
Fix panics in streaming completions handler (#60474)

(cherry picked from commit 52dffbb)

Co-authored-by: Cezary Bartoszuk <cezary.bartoszuk@sourcegraph.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cody Attributions panic

3 participants