Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kostasrim
Copy link
Collaborator

@kostasrim kostasrim commented Jul 10, 2025

Handle WRITE_IN_PROGRESS and READ_IN_PROGRESS. Specifically, when an operation is is progress we can no longer preempt because the context the IO operation is running does not allow preemption (it's not an actual fiber but a function). To solve this, we add a pending member variable which we set when a read or a write is in progress. When the IO operation we got blocked completes it will also resume/handle the pending one.

  • handle write/read in progress
  • add test for partial read/write

@codecov-commenter
Copy link

codecov-commenter commented Jul 10, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 96.96970% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.26%. Comparing base (d30de86) to head (10c4143).
⚠️ Report is 227 commits behind head on master.

Files with missing lines Patch % Lines
util/tls/tls_socket.cc 88.37% 5 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #429      +/-   ##
==========================================
+ Coverage   77.60%   79.26%   +1.65%     
==========================================
  Files         103      112       +9     
  Lines        7824    10282    +2458     
==========================================
+ Hits         6072     8150    +2078     
- Misses       1752     2132     +380     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kostasrim kostasrim self-assigned this Jul 10, 2025
@romange romange requested a review from Copilot August 18, 2025 07:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements handling for WRITE_IN_PROGRESS and READ_IN_PROGRESS states in TLS socket operations to prevent deadlocks when multiple async operations are attempted concurrently. When an I/O operation is in progress and cannot be preempted, the implementation now queues pending operations using a blocked_async_req_ member variable.

  • Added blocking mechanism using blocked_async_req_ to handle concurrent read/write operations
  • Implemented RunBlocked() method to resume pending operations when current operations complete
  • Added comprehensive test coverage for partial read/write scenarios and renegotiation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
util/tls/tls_socket.h Added blocked_async_req_ member and RunBlocked() method declaration
util/tls/tls_socket.cc Implemented blocking logic and RunBlocked() method to handle concurrent operations
util/tls/tls_socket_test.cc Added test classes for partial read/write operations and TLS renegotiation scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

auto* blocked = std::exchange(owner_->blocked_async_req_, nullptr);

if (blocked->should_read_) {
should_read_ = false;
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting should_read_ = false on the current request (this) instead of the blocked request appears incorrect. This should likely be blocked->should_read_ = false; to clear the flag on the request that's about to be processed.

Suggested change
should_read_ = false;
blocked->should_read_ = false;

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to double check this but it suffices to set it to false for the current operation. Will get back to this.

return;
}

if (blocked->role_ == Role::WRITER) {
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic assumes that if the blocked request is not a writer, it must be a reader, but there's no explicit check for Role::READER. Consider adding an explicit check or an else-if clause to make the intent clearer and handle unexpected role values.

Copilot uses AI. Check for mistakes.

return;
}
auto current = std::move(owner_->async_read_req_);
owner_->AsyncReadSome(current->vec_, current->len_, std::move(current->caller_completion_cb_));
Copy link

Copilot AI Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the write case, moving async_read_req_ before calling AsyncReadSome could be problematic since AsyncReadSome likely expects async_read_req_ to be null to create a new request.

Suggested change
owner_->AsyncReadSome(current->vec_, current->len_, std::move(current->caller_completion_cb_));
// Extract data before resetting async_read_req_
auto* current = owner_->async_read_req_.get();
auto vec = current->vec_;
auto len = current->len_;
auto cb = std::move(current->caller_completion_cb_);
owner_->async_read_req_.reset();
owner_->AsyncReadSome(vec, len, std::move(cb));

Copilot uses AI. Check for mistakes.


void AsyncProgressCb(io::Result<size_t> result);

void RunBlocked();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment what this and blocked_async_req_ are?
What is blocked in this context?

@kostasrim kostasrim requested a review from romange October 23, 2025 08:04
@kostasrim kostasrim merged commit a558b5c into romange:master Oct 23, 2025
8 checks passed
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.

3 participants