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

do not start a second GetNextMessageAsync thread in case one is already running #4354

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
16 changes: 15 additions & 1 deletion src/Agent.Listener/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using Agent.Sdk.Knob;
using Microsoft.TeamFoundation.TestClient.PublishTestResults.Telemetry;
using Microsoft.VisualStudio.Services.Agent.Listener.Telemetry;
using System.Collections.Generic;
Expand Down Expand Up @@ -356,15 +357,28 @@ private async Task<int> RunAsync(AgentSettings settings, bool runOnce = false)
Task<bool> selfUpdateTask = null;
bool runOnceJobReceived = false;
jobDispatcher = HostContext.CreateService<IJobDispatcher>();

// check if parallel polling should be prevented
bool preventParallelPolling = AgentKnobs.PreventParallelPolling.GetValue(UtilKnobValueContext.Instance()).AsBoolean();
TaskAgentMessage previuosMessage = null;

Task<TaskAgentMessage> getNextMessage = null;
merlynomsft marked this conversation as resolved.
Show resolved Hide resolved
while (!HostContext.AgentShutdownToken.IsCancellationRequested)
{
TaskAgentMessage message = null;
bool skipMessageDeletion = false;
try
{
Task<TaskAgentMessage> getNextMessage = _listener.GetNextMessageAsync(messageQueueLoopTokenSource.Token);
// if preventing of parallel polling is enabled then check if a getNextMessage thread is already running
// and do not start a new getNextMessage thread if that is the case
if(!preventParallelPolling ||
(getNextMessage == null || (getNextMessage.Status != TaskStatus.Running &&
getNextMessage.Status != TaskStatus.WaitingForChildrenToComplete &&
getNextMessage.Status != TaskStatus.WaitingForActivation &&
getNextMessage.Status != TaskStatus.WaitingToRun)))
{
getNextMessage = _listener.GetNextMessageAsync(messageQueueLoopTokenSource.Token);
}
if (autoUpdateInProgress)
{
Trace.Verbose("Auto update task running at backend, waiting for getNextMessage or selfUpdateTask to finish.");
Expand Down
6 changes: 6 additions & 0 deletions src/Agent.Sdk/Knob/AgentKnobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ public class AgentKnobs
new EnvironmentKnobSource("ENABLE_VS_PRERELEASE_VERSIONS"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob PreventParallelPolling = new Knob(
nameof(PreventParallelPolling),
"If true, the agent will prevent erroneous parallel polling of the agent pool message queue (currently experimental).",
new EnvironmentKnobSource("PREVENT_PARALLEL_POLLING"),
new BuiltInDefaultKnobSource("false"));

public static readonly Knob DisableOverrideTfvcBuildDirectory = new Knob(
nameof(DisableOverrideTfvcBuildDirectory),
"Disables override of Tfvc build directory name by agentId on hosted agents (one tfvc repo used).",
Expand Down
Loading