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.
Description
Currently we're relying on the
SO_SNDTIMEO
andSO_RCVTIMEO
socket options for connect/read/write timeouts. As of CRuby 3.0, sockets are non-blocking by default which means that these socket options do not have any effect by default:https://man7.org/linux/man-pages/man7/socket.7.html
This is easily testable by using Toxiproxy to inject latency to an upstream Memcached:
memcached -d
toxiproxy-cli create -l localhost:22122 -u localhost:11211 memcached_latency
toxiproxy-cli toxic add -t latency -a latency=5000
c = Dalli::Client.new("127.0.0.1:22122", socket_timeout: 0.05)
c.set("foo", "bar", 0, raw: true)
and notice that it hangs for 10s (5s for the initialversion
call when establishing a connection and 5s for theset
operation)Then checkout
nickamorim/io-timeout
and you should get the following error:Proposed Solution
This PR uses the
IO#timeout
feature added in https://bugs.ruby-lang.org/issues/18630 to set a timeout for read, write, and connect calls.Note: I understand that it's non-ideal to have a singular timeout for read, write, and connect calls. I can fix this in a follow-up PR.