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

kad/executor: Add timeout for writting frames #277

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

lexnv
Copy link
Collaborator

@lexnv lexnv commented Oct 29, 2024

This PR adds a WRITE_TIMEOUT for sending frames to remote peers.

The WRITE_TIMEOUT is set to 15 seconds to mirror the READ_TIMEOUT.

Closes: #231

@lexnv lexnv added the enhancement New feature or request label Oct 29, 2024
@lexnv lexnv self-assigned this Oct 29, 2024
@@ -91,16 +93,24 @@ impl QueryExecutor {
/// Send message to remote peer.
pub fn send_message(&mut self, peer: PeerId, message: Bytes, mut substream: Substream) {
self.futures.push(Box::pin(async move {
match substream.send_framed(message).await {
Ok(_) => QueryContext {
match tokio::time::timeout(WRITE_TIMEOUT, substream.send_framed(message)).await {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if you already considered this, but a timeout is typically not needed for write operations, because send_framed(message)).await will return an error if ACK is not received for sent data on the stream level.

On the other hand, the timeout can complicate sending bigger payloads on slow connections, so I would be extra careful when adding it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thinking about it again, it should be safe to add a 15-sec timeout for writing if we already have a 15-sec timeout for reading 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I missed that ACK on the stream level implementation 🤔 Yep, I would keep the timeout more as a safety net in case we do anything wrong on the lower level implementations 🙏

@lexnv lexnv merged commit 9ad20ff into master Oct 30, 2024
8 checks passed
@lexnv lexnv deleted the lexnv/kad-executor-timeout branch October 30, 2024 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kad: Include a timeout for QueryExecutor::send_message
2 participants