Skip to content

Commit e9637fc

Browse files
authored
fixing issue with worker indexing, dotnet-isolated, and placeholders (#9253)
1 parent 1ac40ad commit e9637fc

32 files changed

+386
-81
lines changed

NuGet.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<add key="AzureFunctions@staging" value="https://azfunc.pkgs.visualstudio.com/e6a70c92-4128-439f-8012-382fe78d6396/_packaging/AzureFunctions%40staging/nuget/v3/index.json" />
1010
<add key="AzureFunctionsRelease" value="https://azfunc.pkgs.visualstudio.com/e6a70c92-4128-439f-8012-382fe78d6396/_packaging/AzureFunctionsRelease/nuget/v3/index.json" />
1111
<add key="AzureFunctionsPreRelease" value="https://azfunc.pkgs.visualstudio.com/e6a70c92-4128-439f-8012-382fe78d6396/_packaging/AzureFunctionsPreRelease/nuget/v3/index.json" />
12+
<add key="AzureFunctionsTempStaging" value="https://azfunc.pkgs.visualstudio.com/e6a70c92-4128-439f-8012-382fe78d6396/_packaging/AzureFunctionsTempStaging/nuget/v3/index.json" />
1213
<!-- dotnet-tools is required for Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit -->
1314
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json"/>
1415
</packageSources>

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
[ [bugs](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+143%22+label%3Abug+is%3Aclosed) | [features](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+143%22+label%3Afeature+is%3Aclosed) ]
1212
- Update PowerShell Worker 7.2 to 4.0.2803 [Release Note](https://github.com/Azure/azure-functions-powershell-worker/releases/tag/v4.0.2803)
1313
- Update PowerShell Worker 7.4 to 4.0.2802 [Release Note](https://github.com/Azure/azure-functions-powershell-worker/releases/tag/v4.0.2802)
14+
- Fixing bug with placeholder misses in dotnet-isolated #9253

src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,8 @@ internal void ProcessFunctionMetadataResponses(FunctionMetadataResponse function
845845
FunctionDirectory = metadata.Directory,
846846
ScriptFile = metadata.ScriptFile,
847847
EntryPoint = metadata.EntryPoint,
848-
Name = metadata.Name
848+
Name = metadata.Name,
849+
Language = metadata.Language
849850
};
850851

851852
functionMetadata.SetFunctionId(metadata.FunctionId);

src/WebJobs.Script/Host/FunctionMetadataManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ internal ImmutableArray<FunctionMetadata> LoadFunctionMetadata(bool forceRefresh
135135
ImmutableArray<FunctionMetadata> immutableFunctionMetadata;
136136
var workerConfigs = _languageWorkerOptions.CurrentValue.WorkerConfigs;
137137

138-
immutableFunctionMetadata = _functionMetadataProvider.GetFunctionMetadataAsync(workerConfigs, SystemEnvironment.Instance, forceRefresh).GetAwaiter().GetResult();
138+
immutableFunctionMetadata = _functionMetadataProvider.GetFunctionMetadataAsync(workerConfigs, _environment, forceRefresh).GetAwaiter().GetResult();
139139

140140
var functionMetadataList = new List<FunctionMetadata>();
141141
_functionErrors = new Dictionary<string, ICollection<string>>();

src/WebJobs.Script/Host/FunctionMetadataProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT License. See License.txt in the project root for license information.
33

4-
using System;
54
using System.Collections.Generic;
65
using System.Collections.Immutable;
76
using System.Threading.Tasks;
@@ -21,13 +20,14 @@ internal class FunctionMetadataProvider : IFunctionMetadataProvider
2120
private IWorkerFunctionMetadataProvider _workerFunctionMetadataProvider;
2221
private IHostFunctionMetadataProvider _hostFunctionMetadataProvider;
2322

24-
public FunctionMetadataProvider(ILogger<FunctionMetadataProvider> logger, IWorkerFunctionMetadataProvider workerFunctionMetadataProvider, IHostFunctionMetadataProvider hostFunctionMetadataProvider, IOptions<FunctionsHostingConfigOptions> functionsHostingConfigOptions)
23+
public FunctionMetadataProvider(ILogger<FunctionMetadataProvider> logger, IWorkerFunctionMetadataProvider workerFunctionMetadataProvider, IHostFunctionMetadataProvider hostFunctionMetadataProvider,
24+
IOptions<FunctionsHostingConfigOptions> functionsHostingConfigOptions, IEnvironment environment)
2525
{
2626
_logger = logger;
2727
_workerFunctionMetadataProvider = workerFunctionMetadataProvider;
2828
_hostFunctionMetadataProvider = hostFunctionMetadataProvider;
2929
_functionsHostingConfigOptions = functionsHostingConfigOptions.Value;
30-
_environment = SystemEnvironment.Instance;
30+
_environment = environment;
3131
}
3232

3333
public ImmutableDictionary<string, ImmutableArray<string>> FunctionErrors { get; private set; }

src/WebJobs.Script/Host/WorkerFunctionMetadataProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public async Task<FunctionMetadataResult> GetFunctionMetadataAsync(IEnumerable<R
6565

6666
if (channels?.Any() != true)
6767
{
68-
await _channelManager.InitializeChannelAsync(_workerRuntime);
68+
await _channelManager.InitializeChannelAsync(workerConfigs, _workerRuntime);
6969
channels = _channelManager.GetChannels(_workerRuntime);
7070
}
7171
// start up GRPC channels
@@ -162,7 +162,7 @@ internal IEnumerable<FunctionMetadata> ValidateMetadata(IEnumerable<RawFunctionM
162162
{
163163
Utility.ValidateName(function.Name);
164164

165-
function.Language = SystemEnvironment.Instance.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName);
165+
function.Language = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName);
166166

167167
// skip function directory validation because this involves reading function.json
168168

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ internal async Task InitializeWebhostLanguageWorkerChannel(IEnumerable<string> l
172172
foreach (string language in languages)
173173
{
174174
_logger.LogDebug("Creating new webhost language worker channel for runtime:{workerRuntime}.", language);
175-
IRpcWorkerChannel workerChannel = await _webHostLanguageWorkerChannelManager.InitializeChannelAsync(language);
175+
IRpcWorkerChannel workerChannel = await _webHostLanguageWorkerChannelManager.InitializeChannelAsync(_workerConfigs, language);
176176

177177
// if the worker is indexing, we will not have function metadata yet. So, we cannot set up invocation buffers or send load requests
178178
workerChannel.SetupFunctionInvocationBuffers(_functions);

src/WebJobs.Script/Workers/Rpc/IWebHostRpcWorkerChannelManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.Azure.WebJobs.Script.Workers.Rpc
99
{
1010
public interface IWebHostRpcWorkerChannelManager
1111
{
12-
Task<IRpcWorkerChannel> InitializeChannelAsync(string language);
12+
Task<IRpcWorkerChannel> InitializeChannelAsync(IEnumerable<RpcWorkerConfig> workerConfigs, string language);
1313

1414
Dictionary<string, TaskCompletionSource<IRpcWorkerChannel>> GetChannels(string language);
1515

src/WebJobs.Script/Workers/Rpc/RpcInitializationService.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ public class RpcInitializationService : IManagedHostedService
1818
private readonly IWebHostRpcWorkerChannelManager _webHostRpcWorkerChannelManager;
1919
private readonly IRpcServer _rpcServer;
2020
private readonly ILogger _logger;
21+
private readonly IOptionsMonitor<LanguageWorkerOptions> _languageWorkerOptions;
2122

2223
private readonly string _workerRuntime;
2324
private readonly int _rpcServerShutdownTimeoutInMilliseconds;
2425
private HashSet<string> _placeholderLanguageWorkersList = new HashSet<string>();
2526

26-
public RpcInitializationService(IOptionsMonitor<ScriptApplicationHostOptions> applicationHostOptions, IEnvironment environment, IRpcServer rpcServer, IWebHostRpcWorkerChannelManager rpcWorkerChannelManager, ILogger<RpcInitializationService> logger)
27+
public RpcInitializationService(IOptionsMonitor<ScriptApplicationHostOptions> applicationHostOptions, IEnvironment environment, IRpcServer rpcServer,
28+
IWebHostRpcWorkerChannelManager rpcWorkerChannelManager, ILogger<RpcInitializationService> logger, IOptionsMonitor<LanguageWorkerOptions> languageWorkerOptions)
2729
{
2830
_applicationHostOptions = applicationHostOptions ?? throw new ArgumentNullException(nameof(applicationHostOptions));
2931
_logger = logger;
@@ -33,6 +35,7 @@ public RpcInitializationService(IOptionsMonitor<ScriptApplicationHostOptions> ap
3335
_webHostRpcWorkerChannelManager = rpcWorkerChannelManager ?? throw new ArgumentNullException(nameof(rpcWorkerChannelManager));
3436
_workerRuntime = _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeSettingName);
3537
_placeholderLanguageWorkersList = _environment.GetLanguageWorkerListToStartInPlaceholder();
38+
_languageWorkerOptions = languageWorkerOptions;
3639
}
3740

3841
public async Task StartAsync(CancellationToken cancellationToken)
@@ -116,7 +119,7 @@ internal Task InitializeChannelsAsync()
116119
if (_placeholderLanguageWorkersList.Count() != 0)
117120
{
118121
return Task.WhenAll(_placeholderLanguageWorkersList.Select(runtime =>
119-
_webHostRpcWorkerChannelManager.InitializeChannelAsync(runtime)));
122+
_webHostRpcWorkerChannelManager.InitializeChannelAsync(_languageWorkerOptions.CurrentValue.WorkerConfigs, runtime)));
120123
}
121124
}
122125
return Task.CompletedTask;

src/WebJobs.Script/Workers/Rpc/RpcWorkerProcess.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal class RpcWorkerProcess : WorkerProcess
2323
private readonly WorkerProcessArguments _workerProcessArguments;
2424
private readonly string _workerDirectory;
2525
private readonly IOptions<FunctionsHostingConfigOptions> _hostingConfigOptions;
26+
private readonly IEnvironment _environment;
2627

2728
internal RpcWorkerProcess(string runtime,
2829
string workerId,
@@ -36,7 +37,8 @@ internal RpcWorkerProcess(string runtime,
3637
IWorkerConsoleLogSource consoleLogSource,
3738
IMetricsLogger metricsLogger,
3839
IServiceProvider serviceProvider,
39-
IOptions<FunctionsHostingConfigOptions> hostingConfigOptions)
40+
IOptions<FunctionsHostingConfigOptions> hostingConfigOptions,
41+
IEnvironment environment)
4042
: base(eventManager, processRegistry, workerProcessLogger, consoleLogSource, metricsLogger, serviceProvider, rpcWorkerConfig.Description.UseStdErrorStreamForErrorsOnly)
4143
{
4244
_runtime = runtime;
@@ -49,13 +51,15 @@ internal RpcWorkerProcess(string runtime,
4951
_workerProcessArguments = rpcWorkerConfig.Arguments;
5052
_workerDirectory = rpcWorkerConfig.Description.WorkerDirectory;
5153
_hostingConfigOptions = hostingConfigOptions;
54+
_environment = environment;
5255
}
5356

5457
internal override Process CreateWorkerProcess()
5558
{
5659
var workerContext = new RpcWorkerContext(Guid.NewGuid().ToString(), RpcWorkerConstants.DefaultMaxMessageLengthBytes, _workerId, _workerProcessArguments, _scriptRootPath, _serverUri);
5760
workerContext.EnvironmentVariables.Add(WorkerConstants.FunctionsWorkerDirectorySettingName, _workerDirectory);
5861
workerContext.EnvironmentVariables.Add(WorkerConstants.FunctionsApplicationDirectorySettingName, _scriptRootPath);
62+
workerContext.EnvironmentVariables.Add(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName, _environment.GetEnvironmentVariable(RpcWorkerConstants.FunctionWorkerRuntimeVersionSettingName));
5963
foreach (var pair in _hostingConfigOptions.Value.Features)
6064
{
6165
workerContext.EnvironmentVariables[pair.Key] = pair.Value;

0 commit comments

Comments
 (0)