ICacheClientAsync.SetAsync never time-outs

I ran into an interesting problem with ICacheClientAsync.SetAsync method (version 8.2.2) not timing-out despite setting time-out limits (DefaultConnectTimeout, DefaultSendTimeout, and DefaultReceiveTimeout) to 120 seconds. Below is the problematic task that never completes extracted from the process dump file.

<< Awaiting: 000001c3de94c560 00007ffc9fb22aa8 System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable<System.Int32>+ConfiguredValueTaskAwaiter >>
  000001c3de94c4d8 00007ffca36d2e00 (0) ServiceStack.Redis.BufferedReader+<<ReadByteSlowAsync>g__Awaited|1_0>d @ 7ffca426cdd0
    000001c3de94c578 00007ffca377fbe0 (0) ServiceStack.Redis.RedisNativeClient+<ExpectSuccessAsync>d__649 @ 7ffca4c73f60
      000001c3de94c618 00007ffca39a0118 (0) ServiceStack.Redis.RedisNativeClient+<<ExpectSuccessFnAsync>g__Awaited|648_0>d @ 7ffca4c745c0
        000001c3de94c6a8 00007ffca39a08a8 (1) ServiceStack.Redis.RedisNativeClient+<SendReceiveAsync>d__636<System.Int64> @ 7ffca379cf80
          000001c3de94c7b0 00007ffca39a1e48 (0) ServiceStack.Redis.Internal.ValueTask_Utils+<<Await>g__Awaited|0_0>d<System.Int64> @ 7ffca4c74890
            000001c3de94c848 00007ffca39a2230 (0) ServiceStack.Redis.RedisClient+<ExecAsync>d__19 @ 7ffca4c74b20
              000001c05e150ce0 00007ffca39a2788 (0) ServiceStack.Redis.Internal.ValueTask_Utils+<<AwaitAsTrueTask>g__Awaited|5_0>d @ 7ffca4c74f30

I figured that would most likely happen if no response is received from Redis server. I could probably enforce time-out by passing a cancellation token however that doesn’t resolve the issue with calling sync methods that don’t accept cancellation tokens. Any ideas?

If you were using .NET 8 our .NET 8 build was missing a conditional build symbol preventing it from using an optimal code path which has now been updated in the pre-release packages.

Otherwise yeah passing and cancelling a CancellationToken is the way to as it’s trying to read from a buffered stream which it appears to be blocking on.

Do you know why a Set command is taking so long? Is the Redis Server unreachable or unresponsive?

Redis server is reachable and responsive however due to some unknown reason no response is ever received by the client. Socket connection seems to be OK as no exception is being thrown during reading from the NetworkStream as per Microsoft’s documentation. Still troubleshooting whether this is a Redis server or infrastructure related issue.

As I can see set time-out values (DefaultSendTimeout and DefaultReceiveTimeout) are applied for sync calls but completely ignored for async calls. Would you maybe consider applying time-out values for async calls too? HttpClient is a nice example how it can be done by combining multiple cancellation tokens.

Both Sync and Async connections use the same Socket connection that’s configured with the same Send/Receive timeouts:

I’ve just added linked CancellationTokens to timeout async operations after the configured SendTimeout/ReceiveTimeout if they’ve been configured.

This change is available from v8.7.1+ that’s now available in the pre release packages.