Skip to content

Commit 70d1c61

Browse files
mhoegeryojagad
authored andcommitted
Do not treat 'did not find initialized language workers' as a user exception (#5803)
* do not treat 'did not find initialized language workers' as a user code exception * update comment * typo * remove full try catch
1 parent ef65e5b commit 70d1c61

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,17 @@ public async Task ShutdownAsync()
234234

235235
public async Task InvokeAsync(ScriptInvocationContext invocationContext)
236236
{
237-
try
237+
// This could throw if no initialized workers are found. Shut down instance and retry.
238+
IEnumerable<IRpcWorkerChannel> workerChannels = await GetInitializedWorkerChannelsAsync();
239+
var rpcWorkerChannel = _functionDispatcherLoadBalancer.GetLanguageWorkerChannel(workerChannels, _maxProcessCount);
240+
if (rpcWorkerChannel.FunctionInputBuffers.TryGetValue(invocationContext.FunctionMetadata.FunctionId, out BufferBlock<ScriptInvocationContext> bufferBlock))
238241
{
239-
IEnumerable<IRpcWorkerChannel> workerChannels = await GetInitializedWorkerChannelsAsync();
240-
var rpcWorkerChannel = _functionDispatcherLoadBalancer.GetLanguageWorkerChannel(workerChannels, _maxProcessCount);
241-
if (rpcWorkerChannel.FunctionInputBuffers.TryGetValue(invocationContext.FunctionMetadata.FunctionId, out BufferBlock<ScriptInvocationContext> bufferBlock))
242-
{
243-
_logger.LogDebug("Posting invocation id:{InvocationId} on workerId:{workerChannelId}", invocationContext.ExecutionContext.InvocationId, rpcWorkerChannel.Id);
244-
rpcWorkerChannel.FunctionInputBuffers[invocationContext.FunctionMetadata.FunctionId].Post(invocationContext);
245-
}
246-
else
247-
{
248-
throw new InvalidOperationException($"Function:{invocationContext.FunctionMetadata.Name} is not loaded by the language worker: {rpcWorkerChannel.Id}");
249-
}
242+
_logger.LogDebug("Posting invocation id:{InvocationId} on workerId:{workerChannelId}", invocationContext.ExecutionContext.InvocationId, rpcWorkerChannel.Id);
243+
rpcWorkerChannel.FunctionInputBuffers[invocationContext.FunctionMetadata.FunctionId].Post(invocationContext);
250244
}
251-
catch (Exception invokeEx)
245+
else
252246
{
253-
invocationContext.ResultSource.TrySetException(invokeEx);
247+
throw new InvalidOperationException($"Function:{invocationContext.FunctionMetadata.Name} is not loaded by the language worker: {rpcWorkerChannel.Id}");
254248
}
255249
}
256250

0 commit comments

Comments
 (0)