-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix line reader to resolve buffer issues on TLS connections #888
Conversation
The StreamReader usage when reading the server INFO causes buffer issues on the stream, as it is also read in the reader loop. The StreamReader might consume or return the read bytes back, leading to problems when used on a TLS connection with .NET versions lower than 8. This fix removes the StreamReader usage to address these issues.
src/NATS.Client/Connection.cs
Outdated
{ | ||
if (foundCR) | ||
{ | ||
buffer[read - 2] = (byte)'\r'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the first byte is \r
, read
will be 1, and foundCR
will be true
. Walking this loop in my head.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea I think it should be -1 good catch 💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
The StreamReader usage when reading the server INFO causes buffer issues on the stream, as it is also read in the reader loop. The StreamReader might consume or return the read bytes back, leading to problems when used on a TLS connection with .NET versions lower than 8. This fix removes the StreamReader usage to address these issues.
fixes nats-io/nats.net#586 (comment)