Maybe fix votes?#172
Conversation
|
giving a quick test in test server |
There was a problem hiding this comment.
Pull request overview
This PR adjusts the /vote rank-choice interaction flow to better handle “late” Discord component interactions by adding a done signal and cleaning up the registered component handler when voteGetVote returns.
Changes:
- Add a
donechannel to let the component handler stop forwarding interactions aftervoteGetVotecompletes. - Delete the per-message component handler on function exit to avoid leaking entries in
ComponentHandlers. - Add deferred cleanup for channels and handler state.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| defer func() { | ||
| close(done) | ||
| delete(*ComponentHandlers, messageSlug) | ||
| close(selectionChan) | ||
| close(interactionCreateChan) | ||
| }() |
There was a problem hiding this comment.
Closing selectionChan / interactionCreateChan here is unsafe: the component handler can still be invoked after voteGetVote returns (e.g., an interaction already dispatched but not yet executed). In that case the handler’s select { case selectionChan <- ...; case <-done: } may randomly choose the send case after the channel is closed, which will panic (send on closed channel). Prefer not closing these channels at all (they’ll be GC’d), or ensure the handler cannot run concurrently with the closes (e.g., guard with a mutex/once and never select on a send to a potentially-closed channel).
There was a problem hiding this comment.
"they'll be GC'd" what a statement
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
No description provided.