Reading Message Stream Fails To Read Expected Number Of Bytes
ian-hamlet opened this issue · 2 comments
Hi, we have bumped into a couple of scenarios where the ReserveRequest.TryGetJobFromBuffer fails to read messages because the presenting NetworkStream has not not yet 'streamed' all the bytes that were indicated in the message header, the bytes shortfall causes an exception to be thrown.
_tcs.SetException(new Exception("Unable to parse job description"));
The problem can be fixed with an iterative approach making a number of calls to read the expected number of bytes in chunks.
Up to this point we have run millions of messages through the tubes using a simple reserve/process/delete model. It was only when we began to explore multiple reserves circa 10 messages on messages bodies of around 25K in size.
The same issues may surface in the PeekRequest and several other places where the stream.Read assumes that all bytes are ready and waiting within the stream.
Is the repo still active?
Thanks in advance
Wow, I had no idea this was being used in production by anyone. Thanks for using it, I'm glad to hear you found it useful!
The repo isn't really active because I don't need this library for anything. I wrote it to teach myself network programming.
However, I would welcome contributions. I would be happy to replace this nonsense with System.IO.Pipelines. I suspect that replacing "pass around the NetworkStream" with I/O pipelines would alleviate your issue.
Hello Stephen, I've added a fix for the networking code reading larger messages, see the pull request.
Would be nice if you can have a look, and update the package on Nuget if you're happy with the change.