Skip to content

Commit

Permalink
Fix unexpected timeout errors in logs during laptop sleeping.
Browse files Browse the repository at this point in the history
  • Loading branch information
ww898 committed Dec 6, 2023
1 parent 1823afd commit d26a073
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions rd-net/RdFramework/Tasks/RdCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,15 @@ public TRes Sync(TReq request, RpcTimeouts? timeouts = null)
stopwatch.Start();

var timeoutsToUse = RpcTimeouts.GetRpcTimeouts(timeouts);
if (!task.Wait(timeoutsToUse.ErrorAwaitTime))
if (!task.Wait(timeoutsToUse.WarnAwaitTime))
{
throw new TimeoutException($"Sync execution of rpc `{Location}` is timed out in {timeoutsToUse.ErrorAwaitTime.TotalMilliseconds} ms");
}

stopwatch.Stop();

var freezeTime = stopwatch.ElapsedMilliseconds;
if (freezeTime > timeoutsToUse.WarnAwaitTime.TotalMilliseconds)
{
Log.Root.Error("Sync execution of rpc `{0}` executed too long: {1} ms", Location, freezeTime);
var deltaAwaitTime = timeoutsToUse.ErrorAwaitTime - timeoutsToUse.WarnAwaitTime;
var res = deltaAwaitTime > TimeSpan.Zero && task.Wait(deltaAwaitTime);
stopwatch.Stop();

if (!res)
throw new TimeoutException($"Sync execution of rpc `{Location}` is timed out in {timeoutsToUse.ErrorAwaitTime.TotalMilliseconds} ms, the freeze time is {stopwatch.ElapsedMilliseconds} ms");
Log.Root.Error("Sync execution of rpc `{0}` executed too long: {1} ms, the freeze time: {2} ms", Location, timeoutsToUse.WarnAwaitTime.TotalMilliseconds, stopwatch.ElapsedMilliseconds);
}

return task.Result.Value.Unwrap();
Expand Down

0 comments on commit d26a073

Please sign in to comment.