@@ -52,6 +52,7 @@ internal class GrpcWorkerChannel : IRpcWorkerChannel, IDisposable
52
52
private readonly IOptions < WorkerConcurrencyOptions > _workerConcurrencyOptions ;
53
53
private readonly WaitCallback _processInbound ;
54
54
private readonly object _syncLock = new object ( ) ;
55
+ private readonly object _metadataLock = new object ( ) ;
55
56
private readonly Dictionary < MsgType , Queue < PendingItem > > _pendingActions = new ( ) ;
56
57
private readonly ChannelWriter < OutboundGrpcEvent > _outbound ;
57
58
private readonly ChannelReader < InboundGrpcEvent > _inbound ;
@@ -85,6 +86,7 @@ internal class GrpcWorkerChannel : IRpcWorkerChannel, IDisposable
85
86
private IHttpProxyService _httpProxyService ;
86
87
private Uri _httpProxyEndpoint ;
87
88
private System . Timers . Timer _timer ;
89
+ private bool _functionMetadataRequestSent = false ;
88
90
89
91
internal GrpcWorkerChannel (
90
92
string workerId ,
@@ -540,6 +542,8 @@ internal FunctionLoadRequestCollection GetFunctionLoadRequestCollection(IEnumera
540
542
public Task SendFunctionEnvironmentReloadRequest ( )
541
543
{
542
544
_functionsIndexingTask = new TaskCompletionSource < List < RawFunctionMetadata > > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
545
+ _functionMetadataRequestSent = false ;
546
+
543
547
_workerChannelLogger . LogDebug ( "Sending FunctionEnvironmentReloadRequest to WorkerProcess with Pid: '{0}'" , _rpcWorkerProcess . Id ) ;
544
548
IDisposable latencyEvent = _metricsLogger . LatencyEvent ( MetricEventNames . SpecializationEnvironmentReloadRequestResponse ) ;
545
549
@@ -795,22 +799,32 @@ public Task<List<RawFunctionMetadata>> GetFunctionMetadata()
795
799
796
800
internal Task < List < RawFunctionMetadata > > SendFunctionMetadataRequest ( )
797
801
{
798
- // reset indexing task when in case we need to send another request
799
- _functionsIndexingTask = new TaskCompletionSource < List < RawFunctionMetadata > > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
802
+ _workerChannelLogger . LogDebug ( "Fetching worker metadata, FunctionMetadataReceived set to: {functionMetadataReceived}" , _functionMetadataRequestSent ) ;
803
+ if ( ! _functionMetadataRequestSent )
804
+ {
805
+ lock ( _metadataLock )
806
+ {
807
+ if ( ! _functionMetadataRequestSent )
808
+ {
809
+ RegisterCallbackForNextGrpcMessage ( MsgType . FunctionMetadataResponse , _functionLoadTimeout , 1 ,
810
+ msg => ProcessFunctionMetadataResponses ( msg . Message . FunctionMetadataResponse ) , HandleWorkerMetadataRequestError ) ;
800
811
801
- RegisterCallbackForNextGrpcMessage ( MsgType . FunctionMetadataResponse , _functionLoadTimeout , 1 ,
802
- msg => ProcessFunctionMetadataResponses ( msg . Message . FunctionMetadataResponse ) , HandleWorkerMetadataRequestError ) ;
812
+ _workerChannelLogger . LogDebug ( "Sending WorkerMetadataRequest to {language} worker with worker ID {workerID}" , _runtime , _workerId ) ;
803
813
804
- _workerChannelLogger . LogDebug ( "Sending WorkerMetadataRequest to {language} worker with worker ID {workerID}" , _runtime , _workerId ) ;
814
+ // sends the function app directory path to worker for indexing
815
+ SendStreamingMessage ( new StreamingMessage
816
+ {
817
+ FunctionsMetadataRequest = new FunctionsMetadataRequest ( )
818
+ {
819
+ FunctionAppDirectory = _applicationHostOptions . CurrentValue . ScriptPath
820
+ }
821
+ } ) ;
805
822
806
- // sends the function app directory path to worker for indexing
807
- SendStreamingMessage ( new StreamingMessage
808
- {
809
- FunctionsMetadataRequest = new FunctionsMetadataRequest ( )
810
- {
811
- FunctionAppDirectory = _applicationHostOptions . CurrentValue . ScriptPath
823
+ _functionMetadataRequestSent = true ;
824
+ }
812
825
}
813
- } ) ;
826
+ }
827
+
814
828
return _functionsIndexingTask . Task ;
815
829
}
816
830
0 commit comments