Skip to content

Commit 2fc4c70

Browse files
committed
Merge branch 'release/4.x-hotfix' of https://github.com/Azure/azure-functions-host into release/4.x-hotfix
# Conflicts: # build/common.props # release_notes.md # src/WebJobs.Script.WebHost/PreJIT/coldstart.jittrace # src/WebJobs.Script.WebHost/PreJIT/linux.coldstart.jittrace
2 parents 1d97ee0 + afa91f9 commit 2fc4c70

File tree

44 files changed

+1161
-893
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1161
-893
lines changed

build/common.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
<MajorVersion>4</MajorVersion>
7-
<MinorVersion>10</MinorVersion>
8-
<PatchVersion>3</PatchVersion>
7+
<MinorVersion>11</MinorVersion>
8+
<PatchVersion>0</PatchVersion>
99
<BuildNumber Condition="'$(BuildNumber)' == '' ">0</BuildNumber>
1010
<PreviewVersion></PreviewVersion>
1111

release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
- Updated Java Worker Version to [2.4.0](https://github.com/Azure/azure-functions-java-worker/releases/tag/2.4.0)
1010

1111
**Release sprint:** Sprint 128
12-
[ [bugs](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+128%22+label%3Abug+is%3Aclosed) | [features](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+128%22+label%3Afeature+is%3Aclosed) ]
12+
[ [bugs](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+128%22+label%3Abug+is%3Aclosed) | [features](https://github.com/Azure/azure-functions-host/issues?q=is%3Aissue+milestone%3A%22Functions+Sprint+128%22+label%3Afeature+is%3Aclosed) ]

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

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ internal class GrpcWorkerChannel : IRpcWorkerChannel, IDisposable
7373
private TaskCompletionSource<List<RawFunctionMetadata>> _functionsIndexingTask = new TaskCompletionSource<List<RawFunctionMetadata>>(TaskCreationOptions.RunContinuationsAsynchronously);
7474
private TimeSpan _functionLoadTimeout = TimeSpan.FromMinutes(1);
7575
private bool _isSharedMemoryDataTransferEnabled;
76+
private bool _cancelCapabilityEnabled;
7677

7778
private object _syncLock = new object();
7879
private System.Timers.Timer _timer;
@@ -275,6 +276,7 @@ internal void WorkerInitResponse(GrpcEvent initEvent)
275276
_state = _state | RpcWorkerChannelState.Initialized;
276277
_workerCapabilities.UpdateCapabilities(_initMessage.Capabilities);
277278
_isSharedMemoryDataTransferEnabled = IsSharedMemoryDataTransferEnabled();
279+
_cancelCapabilityEnabled = !string.IsNullOrEmpty(_workerCapabilities.GetCapabilityState(RpcWorkerConstants.HandlesInvocationCancelMessage));
278280

279281
if (!_isSharedMemoryDataTransferEnabled)
280282
{
@@ -501,36 +503,58 @@ internal async Task SendInvocationRequest(ScriptInvocationContext context)
501503
_workerChannelLogger.LogDebug($"Function {context.FunctionMetadata.Name} failed to load");
502504
context.ResultSource.TrySetException(_functionLoadErrors[context.FunctionMetadata.GetFunctionId()]);
503505
_executingInvocations.TryRemove(context.ExecutionContext.InvocationId.ToString(), out ScriptInvocationContext _);
506+
return;
504507
}
505508
else if (_metadataRequestErrors.ContainsKey(context.FunctionMetadata.GetFunctionId()))
506509
{
507510
_workerChannelLogger.LogDebug($"Worker failed to load metadata for {context.FunctionMetadata.Name}");
508511
context.ResultSource.TrySetException(_metadataRequestErrors[context.FunctionMetadata.GetFunctionId()]);
509512
_executingInvocations.TryRemove(context.ExecutionContext.InvocationId.ToString(), out ScriptInvocationContext _);
513+
return;
510514
}
511-
else
515+
516+
if (context.CancellationToken.IsCancellationRequested)
512517
{
513-
if (context.CancellationToken.IsCancellationRequested)
514-
{
515-
context.ResultSource.SetCanceled();
516-
return;
517-
}
518-
var invocationRequest = await context.ToRpcInvocationRequest(_workerChannelLogger, _workerCapabilities, _isSharedMemoryDataTransferEnabled, _sharedMemoryManager);
519-
AddAdditionalTraceContext(invocationRequest.TraceContext.Attributes, context);
520-
_executingInvocations.TryAdd(invocationRequest.InvocationId, context);
518+
_workerChannelLogger.LogDebug("Cancellation has been requested, cancelling invocation request");
519+
context.ResultSource.SetCanceled();
520+
return;
521+
}
521522

522-
SendStreamingMessage(new StreamingMessage
523-
{
524-
InvocationRequest = invocationRequest
525-
});
523+
var invocationRequest = await context.ToRpcInvocationRequest(_workerChannelLogger, _workerCapabilities, _isSharedMemoryDataTransferEnabled, _sharedMemoryManager);
524+
AddAdditionalTraceContext(invocationRequest.TraceContext.Attributes, context);
525+
_executingInvocations.TryAdd(invocationRequest.InvocationId, context);
526+
527+
if (_cancelCapabilityEnabled)
528+
{
529+
context.CancellationToken.Register(() => SendInvocationCancel(invocationRequest.InvocationId));
526530
}
531+
532+
SendStreamingMessage(new StreamingMessage
533+
{
534+
InvocationRequest = invocationRequest
535+
});
527536
}
528537
catch (Exception invokeEx)
529538
{
530539
context.ResultSource.TrySetException(invokeEx);
531540
}
532541
}
533542

543+
internal void SendInvocationCancel(string invocationId)
544+
{
545+
_workerChannelLogger.LogDebug($"Sending invocation cancel request for InvocationId {invocationId}");
546+
547+
var invocationCancel = new InvocationCancel
548+
{
549+
InvocationId = invocationId
550+
};
551+
552+
SendStreamingMessage(new StreamingMessage
553+
{
554+
InvocationCancel = invocationCancel
555+
});
556+
}
557+
534558
// gets metadata from worker
535559
public Task<List<RawFunctionMetadata>> GetFunctionMetadata()
536560
{

src/WebJobs.Script.Grpc/MessageExtensions/StatusResultExtensions.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,19 @@ public static bool IsFailure(this StatusResult statusResult, out Exception excep
3030
}
3131

3232
/// <summary>
33-
/// This method is only hit on the invocation code path. enableUserCodeExceptionCapability = feature flag,
34-
/// exposed as a capability that is set by the worker.
33+
/// This method is only hit on the invocation code path.
34+
/// enableUserCodeExceptionCapability = feature flag exposed as a capability that is set by the worker.
3535
/// </summary>
3636
public static bool IsInvocationSuccess<T>(this StatusResult status, TaskCompletionSource<T> tcs, bool enableUserCodeExceptionCapability = false)
3737
{
3838
switch (status.Status)
3939
{
4040
case StatusResult.Types.Status.Failure:
41+
case StatusResult.Types.Status.Cancelled:
4142
var rpcException = GetRpcException(status, enableUserCodeExceptionCapability);
4243
tcs.SetException(rpcException);
4344
return false;
4445

45-
case StatusResult.Types.Status.Cancelled:
46-
tcs.SetCanceled();
47-
return false;
48-
4946
default:
5047
return true;
5148
}
@@ -65,6 +62,7 @@ public static Workers.Rpc.RpcException GetRpcException(StatusResult statusResult
6562
{
6663
return new Workers.Rpc.RpcException(status, ex.Message, ex.StackTrace, ex.Type, ex.IsUserException);
6764
}
65+
6866
return new Workers.Rpc.RpcException(status, ex.Message, ex.StackTrace);
6967
}
7068
return new Workers.Rpc.RpcException(status, string.Empty, string.Empty);

src/WebJobs.Script.WebHost/Configuration/CorsOptionsSetup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public CorsOptionsSetup(IEnvironment env, IOptions<HostCorsOptions> hostCorsOpti
2323

2424
public void Configure(CorsOptions options)
2525
{
26-
if (_env.IsLinuxConsumption())
26+
if (_env.IsAnyLinuxConsumption())
2727
{
2828
string[] allowedOrigins = _hostCorsOptions.Value.AllowedOrigins?.ToArray() ?? Array.Empty<string>();
2929
var policyBuilder = new CorsPolicyBuilder(allowedOrigins);

src/WebJobs.Script.WebHost/Configuration/ScriptApplicationHostOptionsSetup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private bool IsZipDeployment(out bool isScmRunFromPackage)
7676
Utility.IsValidZipSetting(_environment.GetEnvironmentVariable(AzureWebsiteAltZipDeployment)) ||
7777
Utility.IsValidZipSetting(_environment.GetEnvironmentVariable(AzureWebsiteRunFromPackage));
7878

79-
if (!_environment.IsLinuxConsumption())
79+
if (!_environment.IsAnyLinuxConsumption())
8080
{
8181
isScmRunFromPackage = false;
8282
// This check is strong enough for SKUs other than Linux Consumption.

src/WebJobs.Script.WebHost/ContainerManagement/LinuxContainerActivityPublisher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public LinuxContainerActivityPublisher(IOptionsMonitor<StandbyOptions> standbyOp
3838
IMeshServiceClient meshServiceClient, IEnvironment environment,
3939
ILogger<LinuxContainerActivityPublisher> logger, int flushIntervalMs = FlushIntervalMs, int initialFlushIntervalMs = InitialFlushIntervalMs)
4040
{
41-
if (!environment.IsLinuxConsumption())
41+
if (!environment.IsAnyLinuxConsumption())
4242
{
4343
throw new NotSupportedException(
4444
$"{nameof(LinuxContainerActivityPublisher)} is available in Linux consumption environment only");

src/WebJobs.Script.WebHost/ContainerManagement/LinuxContainerInitializationHostService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ public async Task StartAsync(CancellationToken cancellationToken)
3737
_cancellationToken = cancellationToken;
3838

3939
// The service should be registered in Linux Consumption only, but do additional check here.
40-
if (_environment.IsLinuxConsumption())
40+
if (_environment.IsLinuxConsumptionOnAtlas())
4141
{
4242
await ApplyStartContextIfPresent();
4343
}
44+
else if (_environment.IsLinuxConsumptionOnLegion())
45+
{
46+
_logger.LogInformation("Container has (re)started. Waiting for specialization");
47+
}
4448
}
4549

4650
private async Task ApplyStartContextIfPresent()

src/WebJobs.Script.WebHost/Management/FunctionsSyncManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ internal static bool IsSyncTriggersEnvironment(IScriptWebHostEnvironment webHost
214214

215215
// Windows (Dedicated/Consumption)
216216
// Linux Consumption
217-
if ((environment.IsWindowsAzureManagedHosting() || environment.IsLinuxConsumption()) &&
217+
if ((environment.IsWindowsAzureManagedHosting() || environment.IsAnyLinuxConsumption()) &&
218218
!environment.IsContainerReady())
219219
{
220220
// container ready flag not set yet – site not fully specialized/initialized

src/WebJobs.Script.WebHost/Middleware/HostWarmupMiddleware.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task WarmupInvoke(HttpContext httpContext)
5656
if (!_jitTraceHasRun)
5757
{
5858
PreJitPrepare(WarmUpConstants.JitTraceFileName);
59-
if (_environment.IsLinuxConsumption())
59+
if (_environment.IsAnyLinuxConsumption())
6060
{
6161
PreJitPrepare(WarmUpConstants.LinuxJitTraceFileName);
6262
}
@@ -147,7 +147,7 @@ public async Task WarmUp(HttpRequest request)
147147
public static bool IsWarmUpRequest(HttpRequest request, bool inStandbyMode, IEnvironment environment)
148148
{
149149
return inStandbyMode
150-
&& ((environment.IsAppService() && request.IsAppServiceInternalRequest(environment)) || environment.IsLinuxConsumption())
150+
&& ((environment.IsAppService() && request.IsAppServiceInternalRequest(environment)) || environment.IsAnyLinuxConsumption())
151151
&& (request.Path.StartsWithSegments(_warmupRoutePath) || request.Path.StartsWithSegments(_warmupRouteAlternatePath));
152152
}
153153
}

0 commit comments

Comments
 (0)