Skip to content
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

Issue with RSocketProtocol.Handler reading loop #7

Open
davidfowl opened this issue Sep 11, 2019 · 0 comments
Open

Issue with RSocketProtocol.Handler reading loop #7

davidfowl opened this issue Sep 11, 2019 · 0 comments

Comments

@davidfowl
Copy link

while (!cancellation.IsCancellationRequested)
{
var read = await pipereader.ReadAsync(cancellation);
var buffer = read.Buffer;
if (buffer.IsEmpty && read.IsCompleted) { break; }
var position = buffer.Start;
//Due to the nature of Pipelines as simple binary pipes, all Transport adapters assemble a standard message frame whether or not the underlying transport signals length, EoM, etc.
var (Length, IsEndOfMessage) = MessageFramePeek(buffer);
if (buffer.Length < Length + MESSAGEFRAMESIZE) { pipereader.AdvanceTo(buffer.Start, buffer.End); continue; } //Don't have a complete message yet. Tell the pipe that we've evaluated up to the current buffer end, but cannot yet consume it.
await Process(Length, buffer.Slice(position = buffer.GetPosition(MESSAGEFRAMESIZE, position), Length));
pipereader.AdvanceTo(position = buffer.GetPosition(Length, position));
//TODO UNIT TEST- this should work now too!!! Need to evaluate if there is more than one packet in the pipe including edges like part of the length bytes are there but not all.
}

Doesn't properly handle the exit condition and could result in an infinite loop if partial data is sent and the read is completed.

See https://github.com/davidfowl/DocsStaging/blob/master/Pipelines.md#code-samples for more information.

@davidfowl davidfowl changed the title Potential issue with RSocketProtocol.Handler reading loop Issue with RSocketProtocol.Handler reading loop Sep 15, 2019
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 a pull request may close this issue.

1 participant