Skip to content

fix: Implement timeout layer correctly by using timeout#4059

Merged
Xuanwo merged 10 commits intomainfrom
fix-timeout-layer
Jan 24, 2024
Merged

fix: Implement timeout layer correctly by using timeout#4059
Xuanwo merged 10 commits intomainfrom
fix-timeout-layer

Conversation

@Xuanwo
Copy link
Copy Markdown
Member

@Xuanwo Xuanwo commented Jan 23, 2024

TimeoutLayer is using tokio::time::timeout to implement timeout for operations. And IO Operations insides reader, writer will use Pin<Box<tokio::time::Sleep>> to track the timeout.

This might introduce a bit overhead for IO operations, but it's the only way to implement timeout correctly. We used to implement timeout layer in zero cost way that only stores a std::time::Instant and check the timeout by comparing the instant with current time. However, it doesn't works for all cases.

For examples, users TCP connection could be in Busy ESTAB state. In this state, no IO event will be emit. The runtime will never poll our future again. From the application side, this future is hanging forever until this TCP connection is closed for reaching the linux net.ipv4.tcp_retries2 times.

Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
@github-actions github-actions bot requested review from G-XD and dqhl76 January 23, 2024 15:07
@github-actions github-actions bot added the releases-note/fix The PR fixes a bug or has a title that begins with "fix" label Jan 23, 2024
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Signed-off-by: Xuanwo <github@xuanwo.io>
Copy link
Copy Markdown
Member

@PsiACE PsiACE left a comment

Choose a reason for hiding this comment

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

lgtm. Thanks for sharing the blog and the detailed explanation in the code.

@Xuanwo Xuanwo merged commit 5dc2c7e into main Jan 24, 2024
@Xuanwo Xuanwo deleted the fix-timeout-layer branch January 24, 2024 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/fix The PR fixes a bug or has a title that begins with "fix"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants