Skip to content
This repository was archived by the owner on Mar 14, 2026. It is now read-only.

Fix empty buffer handling in TlsHandler#80

Open
maksimkim wants to merge 2 commits intocuteant:mainfrom
maksimkim:fixtlsemptywrite
Open

Fix empty buffer handling in TlsHandler#80
maksimkim wants to merge 2 commits intocuteant:mainfrom
maksimkim:fixtlsemptywrite

Conversation

@maksimkim
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant