mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(coderd/x/chatd): wake after async chat-row UPDATEs commit (#25036)
The async title-generation and turn-summary goroutines launched from processChat run autocommit UPDATEs on the chat row after finishActiveChat has set the chat to pending and signalWake has fired. If the row lock from one of those UPDATEs is held while acquireLoop's processOnce runs, AcquireChats's FOR UPDATE SKIP LOCKED skips the freshly-pending chat and returns no rows. The wake is then consumed with no acquisition, and the chat sits in pending until the next acquireTicker (default 1s). Wake again after each UPDATE commits. The second wake covers the race window without changing the transaction semantics. Closes coder/internal#1500
This commit is contained in:
@@ -8630,6 +8630,10 @@ func (p *Server) updateLastTurnSummary(
|
||||
updatedChat := chat
|
||||
updatedChat.LastTurnSummary = lastTurnSummary
|
||||
p.publishChatPubsubEvent(updatedChat, codersdk.ChatWatchEventKindSummaryChange, nil)
|
||||
|
||||
// AcquireChats uses SKIP LOCKED; re-wake so a wake racing this
|
||||
// UPDATE's row lock does not strand a freshly-pending chat.
|
||||
p.signalWake()
|
||||
}
|
||||
|
||||
func (p *Server) webpushConfigured() bool {
|
||||
|
||||
@@ -262,6 +262,10 @@ func (p *Server) maybeGenerateChatTitle(
|
||||
chat.Title = title
|
||||
generatedTitle.Store(title)
|
||||
p.publishChatPubsubEvent(chat, codersdk.ChatWatchEventKindTitleChange, nil)
|
||||
|
||||
// AcquireChats uses SKIP LOCKED; re-wake so a wake racing this
|
||||
// UPDATE's row lock does not strand a freshly-pending chat.
|
||||
p.signalWake()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user