Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
54 changes: 49 additions & 5 deletions src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,55 @@ internal void FunctionEnvironmentReloadResponse(FunctionEnvironmentReloadRespons

if (res.Result.IsFailure(out Exception reloadEnvironmentVariablesException))
{
_workerChannelLogger.LogError(reloadEnvironmentVariablesException, "Failed to reload environment variables");
_reloadTask.SetException(reloadEnvironmentVariablesException);
if (IsEnvironmentReloadFailureFatalError(res))
Comment thread
kshyju marked this conversation as resolved.
Outdated
{
_workerChannelLogger.LogError(reloadEnvironmentVariablesException, "Failed to reload environment variables");
_reloadTask.SetException(reloadEnvironmentVariablesException);
}
else
{
_reloadTask.SetResult(false);
}
}
else
{
_reloadTask.SetResult(true);
}
_reloadTask.SetResult(true);
latencyEvent.Dispose();
}

/// <summary>
/// Determines whether the environment reload failure should be considered as a fatal error or should be ignored.
/// </summary>
internal bool IsEnvironmentReloadFailureFatalError(FunctionEnvironmentReloadResponse response)
{
var workerRuntime = _environment.GetFunctionsWorkerRuntime();

// Currently we support non fatal environment reload errors for dotnet isolated worker only.
if (workerRuntime != RpcWorkerConstants.DotNetIsolatedLanguageWorkerName)
{
return true;
}

var rpcException = response.Result.Exception;

// Currently the below 2 errors are considered as non fatal.
if (rpcException.Message.StartsWith("Microsoft.Azure.Functions.Worker.EnvironmentReloadNotSupportedException"))
Comment thread
kshyju marked this conversation as resolved.
Outdated
{
_workerChannelLogger.LogDebug(new EventId(422, ScriptConstants.PlaceholderMissDueToBitnessEventName),
Comment thread
kshyju marked this conversation as resolved.
Outdated
" This app is not using the latest version of Microsoft.Azure.Functions.Worker SDK and therefore does not leverage all performance optimizations. See https://aka.ms/azure-functions/dotnet/placeholders for more information.");
return false;
}
if (rpcException.Message.StartsWith("Microsoft.Azure.Functions.Worker.FunctionAppPayloadNotFoundException"))
{
// If no app payload present, we can ignore the error because
// it is possible that the app was created (instance assigned from platform), but no deployment has happened yet.
return false;
}

return true;
}

internal void WorkerInitResponse(GrpcEvent initEvent)
{
_startLatencyMetric?.Dispose();
Expand Down Expand Up @@ -546,7 +588,7 @@ internal FunctionLoadRequestCollection GetFunctionLoadRequestCollection(IEnumera
return functionLoadRequestCollection;
}

public Task SendFunctionEnvironmentReloadRequest()
public Task<bool> SendFunctionEnvironmentReloadRequest()
{
_functionsIndexingTask = new TaskCompletionSource<List<RawFunctionMetadata>>(TaskCreationOptions.RunContinuationsAsynchronously);
_functionMetadataRequestSent = false;
Expand All @@ -566,7 +608,9 @@ public Task SendFunctionEnvironmentReloadRequest()
FunctionEnvironmentReloadRequest = request
});

return _reloadTask.Task;
var environmentReloadRequestResult = _reloadTask.Task;

return environmentReloadRequestResult;
Comment thread
kshyju marked this conversation as resolved.
Outdated
}

public void SendWorkerWarmupRequest()
Expand Down
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.1" />
<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>
Comment thread
kshyju marked this conversation as resolved.
</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" />
Comment thread
kshyju marked this conversation as resolved.
</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();
Comment thread
kshyju marked this conversation as resolved.
.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" />
Comment thread
kshyju marked this conversation as resolved.
</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 @@
{
Comment thread
kshyju marked this conversation as resolved.
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
Loading