Skip to content

Unknown Protocol Operation after reconnect when sending message#2

Open
basbl wants to merge 2 commits into
mainfrom
confirm-connection-issue
Open

Unknown Protocol Operation after reconnect when sending message#2
basbl wants to merge 2 commits into
mainfrom
confirm-connection-issue

Conversation

@basbl

@basbl basbl commented Jun 25, 2026

Copy link
Copy Markdown
Member

While investigating a breaching SLO for eConsent caused by Unknown Protocol Operations I ended up here.

The investigation led me to the Connection::sendMessage-method which after a reconnect does not write the full message to the socket as the running total is not reset.

To me this makes sense as it does look like an obvious oversight. Looking for feedback!

Last commit contains the notes on the investigation. We can decide to keep this if we want and give it a place in the repo (docs) or drop it.

When a message is larger than the connection packet size it is written to the
socket with several fwrite() calls. If the socket dies *after* the first
chunk has been written, Connection::sendMessage() catches the error,
reconnects, and resumes the write loop. The byte offset counter $total must
be reset to 0 so the *whole* message is resent on the fresh socket.

Before the fix $total kept its stale value, so only the tail of the PUB
command was sent on the new connection. The NATS server then saw the tail
bytes as a fresh protocol command and answered `-ERR 'Unknown Protocol
Operation'`.
@basbl basbl requested a review from slknijnenburg June 25, 2026 07:51
@basbl basbl self-assigned this Jun 25, 2026
@basbl basbl requested a review from MattiasAng June 25, 2026 07:51

@MattiasAng MattiasAng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice find. Add it to the list critical bugs in the SDK. 😅

@basbl

basbl commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

Before merging we need to decide whether we want to keep the notes somewhere in a docs folder.

@MattiasAng

MattiasAng commented Jun 25, 2026

Copy link
Copy Markdown
Member

Before merging we need to decide whether we want to keep the notes somewhere in a docs folder.

I'd say move to docs/changelogs.

@basbl basbl force-pushed the confirm-connection-issue branch from dcc5ea2 to 6c2c155 Compare June 25, 2026 10:51
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.

2 participants