Skip to content
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

backoff if we retried polling for more than 50 times in less than 30m… #3232

Merged
merged 4 commits into from
Apr 9, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Runner.Listener/MessageListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)
ArgUtil.NotNull(_settings, nameof(_settings));
bool encounteringError = false;
int continuousError = 0;
int continuousEmptyMessage = 0;
string errorMessage = string.Empty;
Stopwatch heartbeat = new();
heartbeat.Restart();
Expand Down Expand Up @@ -359,15 +360,26 @@ public async Task<TaskAgentMessage> GetNextMessageAsync(CancellationToken token)

if (message == null)
{
continuousEmptyMessage++;
if (heartbeat.Elapsed > TimeSpan.FromMinutes(30))
{
Trace.Info($"No message retrieved from session '{_session.SessionId}' within last 30 minutes.");
heartbeat.Restart();
continuousEmptyMessage = 0;
}
else
{
Trace.Verbose($"No message retrieved from session '{_session.SessionId}'.");
}

if (continuousEmptyMessage > 50)
Copy link
Contributor Author

@aiqiaoy aiqiaoy Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this check to after the "No message retrieved" trace on 372. So the logs

[MessageListener] No message retrieved from session 'b121baf0-675f-40ad-8a22-818222aaf54e'.
[MessageListener] Sleeping for 25.893 seconds before retrying.

instead of

[MessageListener] Sleeping for 25.893 seconds before retrying.
[MessageListener] No message retrieved from session 'b121baf0-675f-40ad-8a22-818222aaf54e'.

{
// retried more than 50 times in less than 30mins and still getting empty message
// something is not right on the service side, backoff for 15-30s before retry
_getNextMessageRetryInterval = BackoffTimerHelper.GetRandomBackoff(TimeSpan.FromSeconds(15), TimeSpan.FromSeconds(30), _getNextMessageRetryInterval);
Trace.Info("Sleeping for {0} seconds before retrying.", _getNextMessageRetryInterval.TotalSeconds);
await HostContext.Delay(_getNextMessageRetryInterval, token);
}

continue;
}
Expand Down