bug: serialize send to allow for concurrent session use#132
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces serialized message sending to enable concurrent session use. Previously, the code allowed concurrent writes which could cause issues with the transport layer that only supports one active writer at a time. The new implementation uses an outbound message queue processed by a dedicated goroutine to serialize all writes.
Key changes:
- Added
sendLoop()goroutine andoutQchannel to serialize all outbound messages - Renamed
pendingReqtopendingRespfor better semantic clarity - Refactored
Do()method to usequeueSend()instead of writing directly to transport
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| session.go | Implements outbound message queue with sendLoop(), queueSend(), and sendMsg() functions; adds outQ channel to Session struct; refactors Do() to use queue-based sending; starts sendLoop goroutine after handshake |
| session_test.go | Updates test to use renamed pendingResp type instead of pendingReq |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3f8636d to
8d85dce
Compare
de5ff0d to
e4c67d7
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e4c67d7 to
e3b428e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 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.
While doing some performance testing it was clear that I ditched the previous serialization for writes. The old v0.0.2 method was just to put all sends behind a mutex. This is a bit more advanced using an outbound queue and writing each message as they come in.