Set the client side SUB IOPub socket subscription *before* we connect #673
+22
−37
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I am hoping this fixes some very strange weirdness we've been seeing ever since we added the
Welcome
message handshake infrastructure. In particular, this error we see in CI a lot:That error comes from here:
ark/crates/amalthea/src/fixtures/dummy_frontend.rs
Lines 185 to 192 in c7cfe6b
Essentially "I was expecting to get a
Welcome
message, but instead got aKernelStatus { Starting }
message"We've been confused about this because we thought that an XPUB socket was supposed to send out a
Welcome
message before anything else when a SUB connects, which should make this impossible. But we've been thinking about it wrong! It's not that the XPUB socket is sending theKernelStatus { Starting }
message first, it's that we've already missed theWelcome
message!Here's my theory about the race condition we are dealing with:
bind()
s firstconnect()
sWelcome
. But SUB has not set any subscriptions, soWelcome
is droppedsubscribe()
s, and then starts waiting onWelcome
KernelStatus { Starting }
KernelStatus { Starting }
instead ofWelcome
, resulting in the above messageThe solution is so simple. Just subscribe before calling
connect()
, so the welcome message can't get dropped. This is even confirmed by the documentation ofZMQ_XPUB_WELCOME_MSG
:In this case
Subscriber = our client side SUB
. So yea, that would explain it.I even dug all the way into the zmq C++ to see where the welcome message is sent out from. It does indeed look like it is sent out exactly once, at
connect()
time, providing a window where we can miss it if we are not subscribed yet!https://github.com/zeromq/libzmq/blob/34f7fa22022bed9e0e390ed3580a1c83ac4a2834/src/xpub.cpp#L56-L65