Skip to content

fix(messaging): synchronize StreamingMessageHandler NetMQ socket sends - #9810

Open
Tyagiquamar wants to merge 1 commit into
QuantConnect:masterfrom
Tyagiquamar:bug-9790-synchronize-streaming-message-handler
Open

Tyagiquamar wants to merge 1 commit into
QuantConnect:masterfrom
Tyagiquamar:bug-9790-synchronize-streaming-message-handler

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Description

Synchronize NetMQ PushSocket sends and disposal in StreamingMessageHandler using a dedicated lock object (_socketLock).

Related Issue

Fixes #9790

Motivation and Context

StreamingMessageHandler.Transmit(Packet packet) sends packets over ZeroMQ via _server.SendMultipartMessage(message) on a NetMQ PushSocket. NetMQ sockets are not thread-safe. When multiple threads (such as algorithm execution and worker/result streaming threads) invoke Transmit or Send concurrently, concurrent NetMQ operations corrupt internal message buffers, crashing the process with NetMQException: Cannot close an uninitialised Msg.

Adding _socketLock synchronizes calls to _server?.SendMultipartMessage(message) and synchronizes resource clean-up during Dispose().

Requires Documentation Change

No

How Has This Been Tested?

  • Verified compilation and static analysis in Docker matching .NET 10.0 runtime (dotnet build Messaging/QuantConnect.Messaging.csproj -c Release) exiting cleanly with 0 errors.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>- or feature-<issue#>-

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.

StreamingMessageHandler concurrent sends crash NetMQ with "Cannot close an uninitialised Msg"

1 participant