Skip to content

fix(coderd/x/chatd): avoid closing poller hint channels - #28746

Merged
ethanndickson merged 3 commits into
mainfrom
fix/chatd-stream-sync-poller-panic
Sep 4, 2026
Merged

fix(coderd/x/chatd): avoid closing poller hint channels#28746
ethanndickson merged 3 commits into
mainfrom
fix/chatd-stream-sync-poller-panic

Conversation

@ethanndickson

@ethanndickson ethanndickson commented Aug 28, 2026

Copy link
Copy Markdown
Member

Closes SEC-515

Prevent a send on closed channel panic when a chat stream unregisters during polling.

The poller no longer owns or closes subscriber channels. This is safe because delivery is guarded by the stream context, and unregister removes the subscriber from future polls.

@linear-code

linear-code Bot commented Aug 28, 2026

Copy link
Copy Markdown

SEC-515

@ethanndickson
ethanndickson marked this pull request as ready for review August 31, 2026 11:41
@ethanndickson
ethanndickson force-pushed the fix/chatd-stream-sync-poller-panic branch from 914e81b to be6c02d Compare August 31, 2026 11:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-02T10:32:56.256137Z f4d45b0 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: be6c02dfcb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/stream_subscribe.go Outdated
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

Comment thread coderd/x/chatd/stream_sync_poller.go Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 087587f96c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ethanndickson ethanndickson changed the title fix(coderd): make chatd stream sync poller a callback fanout to fix send-on-closed-channel panic fix(coderd/x/chatd): avoid closing poller hint channels Sep 2, 2026
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: f4d45b0ae9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…end-on-closed-channel panic

The stream sync poller delivered hints over per-subscriber channels that
unregister closed under the poller mutex, while pollOnce sent on them
from a lock-free snapshot. A subscriber unregistering mid-poll made
pollOnce panic with "send on closed channel", crashing coderd. Any
authenticated user could trigger this by opening and closing chat
streams (GHSA-7x3x-59xg-4hrc).

Convert the poller to a callback fanout, mirroring pubsub.Subscribe:
Register now takes a deliver callback and returns only an unregister
func, unregister is delete-only (nothing is ever closed), and the
consumer funnels poller hints into its existing consumer-owned updateCh
with the same streamCtx guard already used for pubsub hints. This makes
the panic unrepresentable and also removes the nil-poller closed-channel
return that instantly terminated streams via the ok-check.

Adds a regression race test churning register/unregister against
pollOnce; the previous implementation panics under it.
@ethanndickson
ethanndickson force-pushed the fix/chatd-stream-sync-poller-panic branch from f4d45b0 to 518736f Compare September 3, 2026 17:56
@ethanndickson
ethanndickson merged commit ced03dc into main Sep 4, 2026
37 checks passed
@ethanndickson
ethanndickson deleted the fix/chatd-stream-sync-poller-panic branch September 4, 2026 07:55
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 4, 2026

Copy link
Copy Markdown
Member Author

Backport to release/2.35 created: #28977

Copy link
Copy Markdown
Member Author

Backport to release/2.36 created: #28978

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.

2 participants