Repository navigation
fix(sdks/rust): invoke on_disconnect when mutation is queued after disconnect - #6329
Conversation
kim
left a comment
There was a problem hiding this comment.
Thanks for reporting this.
I can see how it is possible for the on_disconnect callback to be skipped. I think this can be fixed with a much smaller diff, however:
fn apply_pending_mutations(&self) -> crate::Result<()> {
while let Ok(Some(mutation)) =
get_lock_sync(&self.pending_mutations_recv).try_next()
{
match self.apply_mutation(mutation) {
Err(crate::Error::Disconnected) => {
return Err(self.end_connection(None));
}
result => result?,
}
}
Ok(())
}Also, instead of expect, just return Error::Disconnected when unbounded_send fails.
|
Updated in 6538803 to adopt the suggested smaller diff: |
|
Thanks @kim ! The head commit (6538803) now implements exactly the shape you suggested: |
aasoni
left a comment
There was a problem hiding this comment.
looks good, I'll rebase the auto-reconnect changes once this lands
|
Hi @Tyagiquamar! Can you please redo the commits with verified signatures? Then I think this is good to merge! |
|
I'm having our bot redo these commits as verified commits. In the future, we may choose to simply close PRs that do not use verified commits. |
…onnect (clockworklabs#6320) Signed-off-by: Mohd Quamar Tyagi <104281681+Tyagiquamar@users.noreply.github.com>
…_connection Signed-off-by: Mohd Quamar Tyagi <104281681+Tyagiquamar@users.noreply.github.com>
163baeb to
e9e02a3
Compare
af4b20d
Description
Fixes an issue where
on_disconnectcallbacks were skipped when mutations (such as reducers or procedures) were queued immediately after callingdisconnect(), or when the WebSocket sender channel dropped unexpectedly.Problem
disconnect()is invoked,PendingMutation::Disconnectis queued into the message pipeline. Any mutation called prior to the mutation queue processing is queued behindDisconnect.Disconnect, it cleans upsend_chan. The subsequent queued mutation then encounterssend_chan == Noneand returnsErr(Error::Disconnected).run_async,run_threaded,run_background_task) caughtDisconnectedviaerror_is_normal_disconnectand returned directly without executingend_connection. As a result,on_disconnectcallbacks were never triggered, and callers were left with silent connection termination.send_chanwas still populated, callingunbounded_sendtriggered a panic on.expect(...), poisoning thesend_chanmutex and crashing the worker task.Solution
try_sendhelper inDbContextImplthat cleanly catches closed channels and routes closure throughend_connectionwithout panicking or poisoning the mutex.run_async,run_threaded, andrun_background_taskto invokeend_connection(None)on normal disconnect errors soon_disconnectis reliably called.Rollback safety impact
n/a
Issue
Closes #6320