Skip to content

Commit 4a1e380

Browse files
authored
backoff if we retried polling for more than 50 times in less than 30m… (actions#3232)
* backoff if we retried polling for more than 50 times in less than 30minutes * run dotnet format * move delay to after no message trace * run dotnet format
1 parent f467e9e commit 4a1e380

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Runner.Listener/MessageListener.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
236236
ArgUtil.NotNull(_settings, nameof(_settings));
237237
bool encounteringError = false;
238238
int continuousError = 0;
239+
int continuousEmptyMessage = 0;
239240
string errorMessage = string.Empty;
240241
Stopwatch heartbeat = new();
241242
heartbeat.Restart();
@@ -359,16 +360,27 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
359360

360361
if (message == null)
361362
{
363+
continuousEmptyMessage++;
362364
if (heartbeat.Elapsed > TimeSpan.FromMinutes(30))
363365
{
364366
Trace.Info($"No message retrieved from session '{_session.SessionId}' within last 30 minutes.");
365367
heartbeat.Restart();
368+
continuousEmptyMessage = 0;
366369
}
367370
else
368371
{
369372
Trace.Verbose($"No message retrieved from session '{_session.SessionId}'.");
370373
}
371374

375+
if (continuousEmptyMessage > 50)
376+
{
377+
// retried more than 50 times in less than 30mins and still getting empty message
378+
// something is not right on the service side, backoff for 15-30s before retry
379+
_getNextMessageRetryInterval = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(30), _getNextMessageRetryInterval);
380+
Trace.Info("Sleeping for {0} seconds before retrying.", _getNextMessageRetryInterval.TotalSeconds);
381+
await HostContext.Delay(_getNextMessageRetryInterval, token);
382+
}
383+
372384
continue;
373385
}
374386

0 commit comments

Comments
 (0)