Skip to content

🧵 Refactor thread synchronization for sending commands#692

Merged
nevans merged 2 commits into
masterfrom
refactor-send_command-thread-sync
Jun 7, 2026
Merged

🧵 Refactor thread synchronization for sending commands#692
nevans merged 2 commits into
masterfrom
refactor-send_command-thread-sync

Conversation

@nevans

@nevans nevans commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

Related to #693, but that handles code that executes in the receiver thread and this handles code that executes in client threads. (Also, this PR is significantly simpler than that one.)

Sending a command must be synchronized:

  • so multiple threads aren't sending simultaneously
  • so sending the command is correctly interleaved with response handlers

But the command's arguments are presumed to be non-shared (or thread-safe), and this validation does not reference any connection state. Also, now that the deadlock condition in #disconnect has been fixed (#686), it's better to handle the invalid response error before releasing the lock.

So, this updates argument validation to run prior to locking and invalid response error handling to run inside the lock.

nevans added 2 commits June 5, 2026 09:40
Sending a command must be synchronized:
* so multiple threads aren't sending simultaneously
* so sending the command is correctly interleaved with response handlers

But the command's arguments are presumed to be non-shared (or
thread-safe).  And this validation does not reference any connection
state.  So the command arguments can be validated _before_ locking.
Now that the deadlock condition in `#disconnect` has been fixed, it's
better to handle the invalid response error before releasing the lock.
@nevans nevans changed the title 🧵 Refactor thread synchronization for send commands 🧵 Refactor thread synchronization for sending commands Jun 7, 2026
@nevans nevans merged commit 255477d into master Jun 7, 2026
50 of 56 checks passed
@nevans nevans deleted the refactor-send_command-thread-sync branch June 7, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant