Skip to content

Commit a0fe5b7

Browse files
Avoiding initialization of multiple processes when a WebHost channel is avaialable and worker indexing is enabled (#8810)
Co-authored-by: Fabio Cavalcante <[email protected]>
1 parent 2dbb781 commit a0fe5b7

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ internal FunctionLoadRequestCollection GetFunctionLoadRequestCollection(IEnumera
367367

368368
public Task SendFunctionEnvironmentReloadRequest()
369369
{
370+
_functionsIndexingTask = new TaskCompletionSource<List<RawFunctionMetadata>>(TaskCreationOptions.RunContinuationsAsynchronously);
370371
_workerChannelLogger.LogDebug("Sending FunctionEnvironmentReloadRequest to WorkerProcess with Pid: '{0}'", _rpcWorkerProcess.Id);
371372
IDisposable latencyEvent = _metricsLogger.LatencyEvent(MetricEventNames.SpecializationEnvironmentReloadRequestResponse);
372373

src/WebJobs.Script/Workers/Rpc/FunctionRegistration/RpcFunctionInvocationDispatcher.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public async Task InitializeAsync(IEnumerable<FunctionMetadata> functions, Cance
312312
Dictionary<string, TaskCompletionSource<IRpcWorkerChannel>> webhostLanguageWorkerChannels = _webHostLanguageWorkerChannelManager.GetChannels(_workerRuntime);
313313
if (webhostLanguageWorkerChannels != null)
314314
{
315-
int countOfReadyChannels = 0;
315+
int workerProcessCount = 0;
316316
foreach (string workerId in webhostLanguageWorkerChannels.Keys.ToList())
317317
{
318318
if (webhostLanguageWorkerChannels.TryGetValue(workerId, out TaskCompletionSource<IRpcWorkerChannel> initializedLanguageWorkerChannelTask))
@@ -327,8 +327,9 @@ public async Task InitializeAsync(IEnumerable<FunctionMetadata> functions, Cance
327327
{
328328
initializedLanguageWorkerChannel.SetupFunctionInvocationBuffers(_functions);
329329
initializedLanguageWorkerChannel.SendFunctionLoadRequests(_managedDependencyOptions.Value, _scriptOptions.FunctionTimeout);
330-
++countOfReadyChannels;
331330
}
331+
332+
++workerProcessCount;
332333
}
333334
catch (Exception ex)
334335
{
@@ -337,7 +338,7 @@ public async Task InitializeAsync(IEnumerable<FunctionMetadata> functions, Cance
337338
}
338339
}
339340
}
340-
StartWorkerProcesses(countOfReadyChannels, InitializeWebhostLanguageWorkerChannel, true, _webHostLanguageWorkerChannelManager.GetChannels(_workerRuntime));
341+
StartWorkerProcesses(workerProcessCount, InitializeWebhostLanguageWorkerChannel, true, _webHostLanguageWorkerChannelManager.GetChannels(_workerRuntime));
341342
}
342343
else
343344
{

0 commit comments

Comments
 (0)