Skip to content

Commit 47e51df

Browse files
mhoegerpragnagopa
authored andcommitted
[Bug fix] Make sure running language worker processes tracked (#3938)
* Work to publish worker ready event => worker process tracked => later able to be disposed * add a test to make sure # running node processes does not change on file change * Fix ShutdownChannels
1 parent cdabb01 commit 47e51df

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/WebJobs.Script/Rpc/LanguageWorkerChannel.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,14 @@ internal void PublishRpcChannelReadyEvent(RpcEvent initEvent)
278278
HandleWorkerError(exc);
279279
return;
280280
}
281-
if (_functionRegistrations == null)
281+
282+
RpcChannelReadyEvent readyEvent = new RpcChannelReadyEvent(_workerId, _workerConfig.Language, this, _initMessage.WorkerVersion, _initMessage.Capabilities);
283+
_eventManager.Publish(readyEvent);
284+
285+
if (_functionRegistrations != null)
282286
{
283-
RpcChannelReadyEvent readyEvent = new RpcChannelReadyEvent(_workerId, _workerConfig.Language, this, _initMessage.WorkerVersion, _initMessage.Capabilities);
284-
_eventManager.Publish(readyEvent);
285-
return;
287+
RegisterFunctions(_functionRegistrations);
286288
}
287-
RegisterFunctions(_functionRegistrations);
288289
}
289290

290291
public void RegisterFunctions(IObservable<FunctionRegistrationContext> functionRegistrations)

src/WebJobs.Script/Rpc/LanguageWorkerChannelManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void ShutdownStandbyChannels(IEnumerable<FunctionMetadata> functions)
186186

187187
public void ShutdownChannels()
188188
{
189-
foreach (string runtime in _workerChannels.Keys)
189+
foreach (string runtime in _workerChannels.Keys.ToList())
190190
{
191191
_logger.LogInformation("Shutting down language worker channel for runtime:{runtime}", runtime);
192192
_workerChannels[runtime]?.Dispose();

test/WebJobs.Script.Tests.Integration/WebHostEndToEnd/SamplesEndToEndTests_Node.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics;
67
using System.IO;
78
using System.Linq;
89
using System.Net;
@@ -426,6 +427,21 @@ await TestHelpers.Await(async () =>
426427
Assert.Equal(initialTimestamp, timestamp);
427428
}
428429

430+
[Fact]
431+
public async Task NodeProcessCount_SameAfterFileChange()
432+
{
433+
// Count number of node processes before restart
434+
int initialProcessCount = GetProcessCountByName("node");
435+
await SharedDirectory_ReloadsOnFileChange();
436+
// Count number of node processes after restart
437+
int proccessCountAfterReload = GetProcessCountByName("node");
438+
Assert.Equal(proccessCountAfterReload, initialProcessCount);
439+
}
440+
private static int GetProcessCountByName(string processName)
441+
{
442+
return Process.GetProcessesByName(processName).Length;
443+
}
444+
429445
[Fact]
430446
public async Task HttpTrigger_Disabled_SucceedsWithAdminKey()
431447
{

0 commit comments

Comments
 (0)