@@ -78,7 +78,7 @@ internal class GrpcWorkerChannel : IRpcWorkerChannel, IDisposable
78
78
private TaskCompletionSource < List < RawFunctionMetadata > > _functionsIndexingTask = new TaskCompletionSource < List < RawFunctionMetadata > > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
79
79
private TimeSpan _functionLoadTimeout = TimeSpan . FromMinutes ( 1 ) ;
80
80
private bool _isSharedMemoryDataTransferEnabled ;
81
- private bool _cancelCapabilityEnabled ;
81
+ private bool ? _cancelCapabilityEnabled ;
82
82
private bool _isWorkerApplicationInsightsLoggingEnabled ;
83
83
84
84
private System . Timers . Timer _timer ;
@@ -357,6 +357,11 @@ internal WorkerInitRequest GetWorkerInitRequest()
357
357
internal void FunctionEnvironmentReloadResponse ( FunctionEnvironmentReloadResponse res , IDisposable latencyEvent )
358
358
{
359
359
_workerChannelLogger . LogDebug ( "Received FunctionEnvironmentReloadResponse from WorkerProcess with Pid: '{0}'" , _rpcWorkerProcess . Id ) ;
360
+
361
+ LogWorkerMetadata ( res . WorkerMetadata ) ;
362
+ UpdateCapabilities ( res . Capabilities ) ;
363
+ _cancelCapabilityEnabled ??= ! string . IsNullOrEmpty ( _workerCapabilities . GetCapabilityState ( RpcWorkerConstants . HandlesInvocationCancelMessage ) ) ;
364
+
360
365
if ( res . Result . IsFailure ( out Exception reloadEnvironmentVariablesException ) )
361
366
{
362
367
_workerChannelLogger . LogError ( reloadEnvironmentVariablesException , "Failed to reload environment variables" ) ;
@@ -375,13 +380,10 @@ internal void WorkerInitResponse(GrpcEvent initEvent)
375
380
_initMessage = initEvent . Message . WorkerInitResponse ;
376
381
_workerChannelLogger . LogDebug ( "Worker capabilities: {capabilities}" , _initMessage . Capabilities ) ;
377
382
378
- if ( _initMessage . WorkerMetadata != null )
379
- {
380
- _initMessage . UpdateWorkerMetadata ( _workerConfig ) ;
381
- var workerMetadata = _initMessage . WorkerMetadata . ToString ( ) ;
382
- _metricsLogger . LogEvent ( MetricEventNames . WorkerMetadata , functionName : null , workerMetadata ) ;
383
- _workerChannelLogger . LogDebug ( "Worker metadata: {workerMetadata}" , workerMetadata ) ;
384
- }
383
+ // In placeholder scenario, the capabilities and worker metadata will not be available
384
+ // until specialization is done (env reload request). So these can be removed from worker init response code path.
385
+ // to do to track this: https://github.com/Azure/azure-functions-host/issues/9019
386
+ LogWorkerMetadata ( _initMessage . WorkerMetadata ) ;
385
387
386
388
if ( _initMessage . Result . IsFailure ( out Exception exc ) )
387
389
{
@@ -395,7 +397,7 @@ internal void WorkerInitResponse(GrpcEvent initEvent)
395
397
UpdateCapabilities ( _initMessage . Capabilities ) ;
396
398
397
399
_isSharedMemoryDataTransferEnabled = IsSharedMemoryDataTransferEnabled ( ) ;
398
- _cancelCapabilityEnabled = ! string . IsNullOrEmpty ( _workerCapabilities . GetCapabilityState ( RpcWorkerConstants . HandlesInvocationCancelMessage ) ) ;
400
+ _cancelCapabilityEnabled ?? = ! string . IsNullOrEmpty ( _workerCapabilities . GetCapabilityState ( RpcWorkerConstants . HandlesInvocationCancelMessage ) ) ;
399
401
400
402
if ( ! _isSharedMemoryDataTransferEnabled )
401
403
{
@@ -413,6 +415,19 @@ internal void WorkerInitResponse(GrpcEvent initEvent)
413
415
_workerInitTask . TrySetResult ( true ) ;
414
416
}
415
417
418
+ private void LogWorkerMetadata ( WorkerMetadata workerMetadata )
419
+ {
420
+ if ( workerMetadata == null )
421
+ {
422
+ return ;
423
+ }
424
+
425
+ workerMetadata . UpdateWorkerMetadata ( _workerConfig ) ;
426
+ var workerMetadataString = workerMetadata . ToString ( ) ;
427
+ _metricsLogger . LogEvent ( MetricEventNames . WorkerMetadata , functionName : null , workerMetadataString ) ;
428
+ _workerChannelLogger . LogDebug ( "Worker metadata: {workerMetadata}" , workerMetadataString ) ;
429
+ }
430
+
416
431
// Allow tests to add capabilities, even if not directly supported by the worker.
417
432
internal virtual void UpdateCapabilities ( IDictionary < string , string > fields )
418
433
{
@@ -668,7 +683,7 @@ await SendStreamingMessageAsync(new StreamingMessage
668
683
InvocationRequest = invocationRequest
669
684
} ) ;
670
685
671
- if ( _cancelCapabilityEnabled )
686
+ if ( _cancelCapabilityEnabled != null && _cancelCapabilityEnabled . Value )
672
687
{
673
688
context . CancellationToken . Register ( ( ) => SendInvocationCancel ( invocationRequest . InvocationId ) ) ;
674
689
}
0 commit comments