-
Notifications
You must be signed in to change notification settings - Fork 5.3k
alts: Fix TsiSocket doWrite on outstanding handshake bytes handling #16488
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
Merged
antoniovicente
merged 13 commits into
envoyproxy:main
from
yihuazhang:tsi_write_fix_new
Jun 16, 2021
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4dd39ad
fix tsi_write
yihuazhang c62dfa2
call raiseEvent() after doWrite()
yihuazhang ec665cd
check connection close before raiseEvent
yihuazhang ee23de6
Merge remote-tracking branch 'upstream/main' into tsi_write_fix_new
yihuazhang 713d4c4
Merged with upstream/main and changed min<size_t> to min<uint64_t>
yihuazhang 0ab3b79
add a test
yihuazhang 9851cbb
fix AltsIntegrationTestValidPeer.RouterRequestAndResponseWithBodyRawHttp
antoniovicente b3917a1
fix a format error
yihuazhang 58e626a
Merge remote-tracking branch 'upstream/main' into tsi_write_fix_new
yihuazhang d3aa25f
remove unused using
yihuazhang a94c14d
Merge remote-tracking branch 'upstream/main' into tsi_write_fix_new
yihuazhang 81d9cc6
Add a test to verify max_frame_size in handshake messages
yihuazhang eecee24
remove actual frame size check due to use-after-free issue
yihuazhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,7 +151,9 @@ Network::PostIoAction TsiSocket::doHandshakeNextDone(NextResultPtr&& next_result | |
| frame_protector_ = std::make_unique<TsiFrameProtector>(frame_protector); | ||
|
|
||
| handshake_complete_ = true; | ||
| callbacks_->raiseEvent(Network::ConnectionEvent::Connected); | ||
| if (raw_write_buffer_.length() == 0) { | ||
| callbacks_->raiseEvent(Network::ConnectionEvent::Connected); | ||
| } | ||
| } | ||
|
|
||
| if (read_error_ || (!handshake_complete_ && end_stream_read_)) { | ||
|
|
@@ -167,8 +169,8 @@ Network::PostIoAction TsiSocket::doHandshakeNextDone(NextResultPtr&& next_result | |
| // Try to write raw buffer when next call is done, even this is not in do[Read|Write] stack. | ||
| if (raw_write_buffer_.length() > 0) { | ||
| Network::IoResult result = raw_buffer_socket_->doWrite(raw_write_buffer_, false); | ||
| if (handshake_complete_ && raw_write_buffer_.length() > 0) { | ||
| write_buffer_contains_handshake_bytes_ = true; | ||
| if (handshake_complete_ && result.action_ != Network::PostIoAction::Close) { | ||
| callbacks_->raiseEvent(Network::ConnectionEvent::Connected); | ||
| } | ||
| return result.action_; | ||
| } | ||
|
|
@@ -266,13 +268,13 @@ Network::IoResult TsiSocket::doRead(Buffer::Instance& buffer) { | |
| Network::IoResult TsiSocket::repeatProtectAndWrite(Buffer::Instance& buffer, bool end_stream) { | ||
| uint64_t total_bytes_written = 0; | ||
| Network::IoResult result = {Network::PostIoAction::KeepOpen, 0, false}; | ||
|
|
||
| ASSERT(!write_buffer_contains_handshake_bytes_); | ||
| // There should be no handshake bytes in raw_write_buffer_. | ||
| ASSERT(!(raw_write_buffer_.length() > 0 && prev_bytes_to_drain_ == 0)); | ||
| while (true) { | ||
| uint64_t bytes_to_drain_this_iteration = | ||
| prev_bytes_to_drain_ > 0 | ||
| ? prev_bytes_to_drain_ | ||
| : std::min<size_t>(buffer.length(), actual_frame_size_to_use_ - frame_overhead_size_); | ||
| : std::min<uint64_t>(buffer.length(), actual_frame_size_to_use_ - frame_overhead_size_); | ||
| // Consumed all data. Exit. | ||
| if (bytes_to_drain_this_iteration == 0) { | ||
| break; | ||
|
|
@@ -327,8 +329,7 @@ Network::IoResult TsiSocket::doWrite(Buffer::Instance& buffer, bool end_stream) | |
| } else { | ||
| ASSERT(frame_protector_); | ||
| // Check if we need to flush outstanding handshake bytes. | ||
| if (write_buffer_contains_handshake_bytes_) { | ||
| ASSERT(raw_write_buffer_.length() > 0); | ||
| if (raw_write_buffer_.length() > 0 && prev_bytes_to_drain_ == 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be helpful to add tests to cover the case where doHandshakeNextDone adds bytes and how this version behaves better than the case where we only set "write_buffer_contains_handshake_bytes_ = true" in one special case. |
||
| ENVOY_CONN_LOG(debug, "TSI: raw_write length {} end_stream {}", callbacks_->connection(), | ||
| raw_write_buffer_.length(), end_stream); | ||
| Network::IoResult result = | ||
|
|
@@ -337,7 +338,6 @@ Network::IoResult TsiSocket::doWrite(Buffer::Instance& buffer, bool end_stream) | |
| if (raw_write_buffer_.length() > 0) { | ||
| return {result.action_, 0, false}; | ||
| } | ||
| write_buffer_contains_handshake_bytes_ = false; | ||
| } | ||
| return repeatProtectAndWrite(buffer, end_stream); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
See https://github.com/envoyproxy/envoy/pull/16514/files
Could you merge upstream/main and consider changing the "std::min<size_t>(" to "std::min<uint64_t>("
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.
Sure thing. Done.