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

Fix empty buffer handling in TlsHandler #80

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

maksimkim
Copy link
Contributor

Problem: promise associated with writing empty buffer to TlsHandler never completes because EmptyByteBuffer doesn't write anything on .ReadBytes call to passed stream:

_ = buf.ReadBytes(_sslStream, readableBytes); // this leads to FinishWrap being called 0+ times

Minimal repro: https://github.com/maksimkim/DotNetty/blob/2a35ea6df4b57f33997cb00702a1c712d6a17c6b/examples/HttpClient/Program.cs#L60

await channel.WriteAndFlushAsync(EmptyLastHttpContent.Default) never completes.

Solution: special case handling for empty buffer

@maksimkim
Copy link
Contributor Author

@cuteant , the change breaks existing TlsHandler tests when checking EmbeddedChannel.Finish():

Assert.False(ch.Finish());

It expects channel not to have any outgoing messages but the Finish() itself causes TlsHandler to write another Unpooled.Empty to the EmbeddedChannel:

_pendingUnencryptedWrites.Add(Unpooled.Empty, promise);

Hence this validation always fails. What's going to be your recommendation on proper fix for the tests?

@maksimkim
Copy link
Contributor Author

@cuteant , also the regression is introduced in this PR: #65
Prior to that the promise for empty buffer write was completed in place without writing to channel:

_ = promise.TryComplete();

I wonder what is the original netty behavior in this situation?

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.

None yet

1 participant