Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,18 @@ internal void FunctionEnvironmentReloadResponse(FunctionEnvironmentReloadRespons

ApplyCapabilities(res.Capabilities, res.CapabilitiesUpdateStrategy.ToGrpcCapabilitiesUpdateStrategy());

if (res.Result.IsFailure(out Exception reloadEnvironmentVariablesException))
if (res.Result.IsFailure(IsUserCodeExceptionCapabilityEnabled(), out var reloadEnvironmentVariablesException))
{
_workerChannelLogger.LogError(reloadEnvironmentVariablesException, "Failed to reload environment variables");
_reloadTask.SetException(reloadEnvironmentVariablesException);
if (res.Result.Exception is not null && reloadEnvironmentVariablesException is not null)
{
_workerChannelLogger.LogWarning(reloadEnvironmentVariablesException, reloadEnvironmentVariablesException.Message);
}
_reloadTask.SetResult(false);
}
else
{
_reloadTask.SetResult(true);
}
_reloadTask.SetResult(true);
latencyEvent.Dispose();
}

Expand Down Expand Up @@ -414,6 +420,15 @@ internal void WorkerInitResponse(GrpcEvent initEvent)
_workerInitTask.TrySetResult(true);
}

private bool IsUserCodeExceptionCapabilityEnabled()
{
var enableUserCodeExceptionCapability = string.Equals(
_workerCapabilities.GetCapabilityState(RpcWorkerConstants.EnableUserCodeException), bool.TrueString,
StringComparison.OrdinalIgnoreCase);

return enableUserCodeExceptionCapability;
}

private void LogWorkerMetadata(WorkerMetadata workerMetadata)
{
if (workerMetadata == null)
Expand Down Expand Up @@ -546,7 +561,7 @@ internal FunctionLoadRequestCollection GetFunctionLoadRequestCollection(IEnumera
return functionLoadRequestCollection;
}

public Task SendFunctionEnvironmentReloadRequest()
public Task<bool> SendFunctionEnvironmentReloadRequest()
{
_functionsIndexingTask = new TaskCompletionSource<List<RawFunctionMetadata>>(TaskCreationOptions.RunContinuationsAsynchronously);
_functionMetadataRequestSent = false;
Expand Down Expand Up @@ -1584,4 +1599,4 @@ private void OnTimeout()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@

using System;
using System.Threading.Tasks;
using Grpc.Core;
using Microsoft.Azure.WebJobs.Script.Config;
using Microsoft.Azure.WebJobs.Script.Grpc.Messages;

namespace Microsoft.Azure.WebJobs.Script.Grpc
{
internal static class StatusResultExtensions
{
public static bool IsFailure(this StatusResult statusResult, out Exception exception)
public static bool IsFailure(this StatusResult statusResult, bool enableUserCodeExceptionCapability, out Exception exception)
{
switch (statusResult.Status)
{
case StatusResult.Types.Status.Failure:
exception = GetRpcException(statusResult);
exception = GetRpcException(statusResult, enableUserCodeExceptionCapability);
return true;

case StatusResult.Types.Status.Cancelled:
Expand All @@ -29,6 +27,11 @@ public static bool IsFailure(this StatusResult statusResult, out Exception excep
}
}

public static bool IsFailure(this StatusResult statusResult, out Exception exception)
{
return IsFailure(statusResult, false, out exception);
}

/// <summary>
/// This method is only hit on the invocation code path.
/// enableUserCodeExceptionCapability = feature flag exposed as a capability that is set by the worker.
Expand Down Expand Up @@ -68,4 +71,4 @@ public static Workers.Rpc.RpcException GetRpcException(StatusResult statusResult
return new Workers.Rpc.RpcException(status, string.Empty, string.Empty);
}
}
}
}
2 changes: 1 addition & 1 deletion src/WebJobs.Script/WebJobs.Script.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.DotNetIsolatedNativeHost" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.DotNetIsolatedNativeHost" Version="1.0.2" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.39" />
<PackageReference Include="Microsoft.Azure.WebJobs.Host.Storage" Version="5.0.0-beta.2-11957" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/WebJobs.Script/Workers/Rpc/IRpcWorkerChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface IRpcWorkerChannel : IWorkerChannel

void SendFunctionLoadRequests(ManagedDependencyOptions managedDependencyOptions, TimeSpan? functionTimeout);

Task SendFunctionEnvironmentReloadRequest();
Task<bool> SendFunctionEnvironmentReloadRequest();

void SendWorkerWarmupRequest();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ public async Task SpecializeAsync()

if (_workerRuntime != null && rpcWorkerChannel != null)
{
bool envReloadRequestResultSuccessful = false;
if (UsePlaceholderChannel(rpcWorkerChannel))
{
_logger.LogDebug("Loading environment variables for runtime: {runtime}", _workerRuntime);
await rpcWorkerChannel.SendFunctionEnvironmentReloadRequest();
envReloadRequestResultSuccessful = await rpcWorkerChannel.SendFunctionEnvironmentReloadRequest();
}
else

if (envReloadRequestResultSuccessful == false)
{
_logger.LogDebug("Shutting down placeholder worker. Worker is not compatible for runtime: {runtime}", _workerRuntime);
// If we need to allow file edits, we should shutdown the webhost channel on specialization.
Expand Down
10 changes: 6 additions & 4 deletions test/DotNetIsolated60/DotNetIsolated60.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<FunctionsEnableWorkerIndexing>True</FunctionsEnableWorkerIndexing>
<FunctionsAutoRegisterGeneratedMetadataProvider>True</FunctionsAutoRegisterGeneratedMetadataProvider>
<FunctionsEnableExecutorSourceGen>True</FunctionsEnableExecutorSourceGen>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.18.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.0.0-preview2" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="6.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.12.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.15.1" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down
6 changes: 6 additions & 0 deletions test/DotNetIsolated60/DotNetIsolated60.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.33627.172
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotNetIsolated60", "DotNetIsolated60.csproj", "{1DA92227-F28E-408D-96B1-20C72571E4AE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetIsolatedUnsupportedWorker", "..\DotNetIsolatedUnsupportedWorker\DotNetIsolatedUnsupportedWorker.csproj", "{3F15B936-6365-447E-9EC6-4E996B30C55F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{1DA92227-F28E-408D-96B1-20C72571E4AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1DA92227-F28E-408D-96B1-20C72571E4AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1DA92227-F28E-408D-96B1-20C72571E4AE}.Release|Any CPU.Build.0 = Release|Any CPU
{3F15B936-6365-447E-9EC6-4E996B30C55F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F15B936-6365-447E-9EC6-4E996B30C55F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F15B936-6365-447E-9EC6-4E996B30C55F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F15B936-6365-447E-9EC6-4E996B30C55F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 2 additions & 4 deletions test/DotNetIsolated60/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
if (useProxy)
{
hostBuilder
.ConfigureFunctionsWebApplication()
.ConfigureGeneratedFunctionMetadataProvider();
.ConfigureFunctionsWebApplication();
}
else
{
hostBuilder
.ConfigureFunctionsWorkerDefaults()
.ConfigureGeneratedFunctionMetadataProvider();
.ConfigureFunctionsWorkerDefaults();
}

var host = hostBuilder.Build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<FunctionsEnableWorkerIndexing>True</FunctionsEnableWorkerIndexing>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="6.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.14.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
30 changes: 30 additions & 0 deletions test/DotNetIsolatedUnsupportedWorker/HttpRequestDataFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;

namespace DotNetIsolatedUnsupportedWorker
{
public class HttpRequestDataFunction
{
private readonly ILogger _logger;

public HttpRequestDataFunction(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<HttpRequestDataFunction>();
}

[Function("HttpRequestDataFunction")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");

var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

response.WriteString("Welcome to Azure Functions!");

return response;
}
}
}
23 changes: 23 additions & 0 deletions test/DotNetIsolatedUnsupportedWorker/HttpRequestFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace DotNetIsolatedUnsupportedWorker
{
public class HttpRequestFunction
{
private readonly ILogger<HttpRequestFunction> _logger;

public HttpRequestFunction(ILogger<HttpRequestFunction> logger)
{
_logger = logger;
}

[Function(nameof(HttpRequestFunction))]
public Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");
return req.HttpContext.Response.WriteAsync("Welcome to Azure Functions!");
}
}
}
23 changes: 23 additions & 0 deletions test/DotNetIsolatedUnsupportedWorker/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Hosting;

//Debugger.Launch();

// Tests can set an env var that will swap this to use the proxy
bool useProxy = Environment.GetEnvironmentVariable("UseProxyInTest")?.Contains("1") ?? false;

var hostBuilder = new HostBuilder();

if (useProxy)
{
hostBuilder
.ConfigureFunctionsWebApplication();
}
else
{
hostBuilder
.ConfigureFunctionsWorkerDefaults();
}

var host = hostBuilder.Build();
host.Run();
21 changes: 21 additions & 0 deletions test/DotNetIsolatedUnsupportedWorker/QueueFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace DotNetIsolatedUnsupportedWorker
{
public class QueueFunction
{
private readonly ILogger _logger;

public QueueFunction(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<QueueFunction>();
}

[Function("QueueFunction")]
public void Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string myQueueItem)
{
_logger.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
}
}
}
12 changes: 12 additions & 0 deletions test/DotNetIsolatedUnsupportedWorker/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
},
"enableLiveMetricsFilters": true
}
}
}
7 changes: 7 additions & 0 deletions test/EmptyScriptRoot/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
Loading