Skip to content

Make PooledSocket.ReadAsync respect receive timeout setting #257

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
merged 1 commit into from
May 18, 2025

Conversation

frodejac
Copy link

We have seen examples of our memcached clients not timing out for several minutes on reads and/or writes in our Kubernetes environment under certain conditions occurring after node rebalancing and subsequent mecached pod rescheduling. This was despite us setting a very short (10ms) receive timeout in the client configuration.

After some digging, we realized that Socket.ReceiveTimeout only affects blocking receive calls. This is well-documented in the Socket.ReceiveTimeout docs, as well as the documentation for the underlying setsockopt documentation (emphasis mine):

SO_RCVTIMEO | DWORD | Sets the timeout, in milliseconds, for blocking receive calls.

This PR wraps calls to NetworkStream.ReadAsync in PooledSocket in a Task.WhenAny(readTask, timeoutTask), a pattern already in use several other places in this codebase for other asynchronous socket operations. I also added tests to verify that the receive timeout setting is respected in both blocking and non-blocking PooledSocket reads.

@cnblogs-dudu cnblogs-dudu self-requested a review May 17, 2025 14:38
@cnblogs-dudu cnblogs-dudu merged commit f93de0b into cnblogs:main May 18, 2025
1 check passed
@cnblogs-dudu cnblogs-dudu self-assigned this May 18, 2025
@cnblogs-dudu cnblogs-dudu removed their request for review May 18, 2025 05:39
@cnblogs-dudu
Copy link

Thanks for your contribution!

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.

2 participants