Skip to content

Fix XPub manual mode: Send between Receive and Subscribe clears m_lastPipe - #1153

Merged
drewnoakes merged 2 commits into
masterfrom
copilot/fix-race-condition-m-lastpipe
Apr 30, 2026
Merged

drewnoakes merged 2 commits into
masterfrom
copilot/fix-race-condition-m-lastpipe

Conversation

Copilot AI commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

In manual mode, XPub.XSend unconditionally set m_lastPipe = null after every completed send. Since m_lastPipe is also used to track the pipe of the most-recently-received subscription (so Subscribe()/Unsubscribe() can target it), any Send() call between ReceiveFrameBytes() and Subscribe() silently dropped the subscription.

Changes

  • XPub.cs — XSend: Only clear m_lastPipe when m_lastPipeIsBroadcast is true. The field is needed for broadcast exclusion, not for general sends; leaving it intact for regular publishes preserves the pipe reference that manual-mode Subscribe()/Unsubscribe() depend on.

  • XPubSubTests.cs — ManualSubscribeAfterSend: New test covering the broken sequence:

// Subscriber sends subscription → publisher receives it (m_lastPipe = sub_pipe)
var subscription = pub.ReceiveFrameBytes();

// A send between receive and subscribe previously wiped m_lastPipe
pub.SendFrame("A");                              // was: m_lastPipe = null ← bug

// Subscribe must still target the correct pipe
pub.Subscribe(subscription.Skip(1).ToArray());  // was: silently no-op

pub.SendFrame("A");
Assert.Equal("A", sub.ReceiveFrameString());    // was: test would hang

Copilot AI changed the title [WIP] Fix intermittent error due to race condition on m_lastPipe field Fix XPub manual mode: Send between Receive and Subscribe clears m_lastPipe Apr 30, 2026
Copilot AI requested a review from drewnoakes April 30, 2026 04:29
@drewnoakes
drewnoakes marked this pull request as ready for review April 30, 2026 12:49
@drewnoakes
drewnoakes merged commit ffe3b37 into master Apr 30, 2026
3 checks passed
@drewnoakes
drewnoakes deleted the copilot/fix-race-condition-m-lastpipe branch April 30, 2026 13:32
follesoe pushed a commit to BluEye-Robotics/netmq that referenced this pull request May 4, 2026
…tPipe (zeromq#1153)

* Initial plan

* Fix race condition on m_lastPipe in XPub manual subscribe mode

Agent-Logs-Url: https://github.com/zeromq/netmq/sessions/c4786470-ce78-4365-a544-f6685acb34b5

Co-authored-by: drewnoakes <350947+drewnoakes@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: drewnoakes <350947+drewnoakes@users.noreply.github.com>
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.

The error occurs intermittently because of a race condition on the m_lastPipe field

2 participants