Skip to content

Commit

Permalink
Send env reload response with "Failure" as Status property value when…
Browse files Browse the repository at this point in the history
… specialization request received and no payload is present. (#1933)
  • Loading branch information
kshyju committed Oct 4, 2023
1 parent 9492b21 commit dfc1801
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions host/src/FunctionsNetHost/Grpc/IncomingGrpcMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,21 @@ private async Task Process(StreamingMessage msg)
Logger.LogTrace("Specialization request received.");

var envReloadRequest = msg.FunctionEnvironmentReloadRequest;
var applicationExePath = PathUtils.GetApplicationExePath(envReloadRequest.FunctionAppDirectory);
Logger.LogTrace($"application path {applicationExePath}");

if (string.IsNullOrWhiteSpace(applicationExePath))
{
var ex = new InvalidOperationException($"Unable to find a valid function app payload at '{envReloadRequest.FunctionAppDirectory}'");
responseMessage.FunctionEnvironmentReloadResponse = BuildFailedEnvironmentReloadResponse(ex);
break;
}

foreach (var kv in envReloadRequest.EnvironmentVariables)
{
EnvironmentUtils.SetValue(kv.Key, kv.Value);
}

var applicationExePath = PathUtils.GetApplicationExePath(envReloadRequest.FunctionAppDirectory);
Logger.LogTrace($"application path {applicationExePath}");

#pragma warning disable CS4014
Task.Run(() =>
#pragma warning restore CS4014
Expand All @@ -74,7 +81,31 @@ private async Task Process(StreamingMessage msg)
break;
}

await MessageChannel.Instance.SendOutboundAsync(responseMessage);
if (responseMessage.ContentCase != StreamingMessage.ContentOneofCase.None)
{
await MessageChannel.Instance.SendOutboundAsync(responseMessage);
}
}

private static FunctionEnvironmentReloadResponse BuildFailedEnvironmentReloadResponse(Exception exception)
{
var rpcException = new RpcException
{
Message = exception.ToString(),
Source = exception.Source ?? string.Empty,
StackTrace = exception.StackTrace ?? string.Empty
};

var response = new FunctionEnvironmentReloadResponse
{
Result = new StatusResult
{
Status = StatusResult.Types.Status.Failure,
Exception = rpcException
}
};

return response;
}

private static FunctionMetadataResponse BuildFunctionMetadataResponse()
Expand Down

0 comments on commit dfc1801

Please sign in to comment.