File tree Expand file tree Collapse file tree 3 files changed +23
-10
lines changed
Expand file tree Collapse file tree 3 files changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -263,15 +263,12 @@ private void AddOrUpdateWorkerChannels(RpcJobHostChannelReadyEvent rpcChannelRea
263263
264264 protected virtual void Dispose ( bool disposing )
265265 {
266- if ( ! _disposed )
266+ if ( ! _disposed && disposing )
267267 {
268- if ( disposing )
269- {
270- _workerErrorSubscription . Dispose ( ) ;
271- _rpcChannelReadySubscriptions . Dispose ( ) ;
272- _workerState . DisposeAndRemoveChannels ( ) ;
273- _workerState . Functions . Dispose ( ) ;
274- }
268+ _workerErrorSubscription . Dispose ( ) ;
269+ _rpcChannelReadySubscriptions . Dispose ( ) ;
270+ _workerState . DisposeAndRemoveChannels ( ) ;
271+ _workerState . Functions . Dispose ( ) ;
275272 _disposed = true ;
276273 }
277274 }
Original file line number Diff line number Diff line change @@ -284,6 +284,11 @@ internal void SendWorkerInitRequest(RpcEvent startEvent)
284284
285285 internal void PublishWorkerProcessReadyEvent ( FunctionEnvironmentReloadResponse res )
286286 {
287+ if ( _disposing )
288+ {
289+ // do not publish ready events when disposing
290+ return ;
291+ }
287292 WorkerProcessReadyEvent wpEvent = new WorkerProcessReadyEvent ( _workerId , _workerConfig . Language ) ;
288293 _eventManager . Publish ( wpEvent ) ;
289294 }
@@ -293,6 +298,11 @@ internal void PublishRpcChannelReadyEvent(RpcEvent initEvent)
293298 _startLatencyMetric ? . Dispose ( ) ;
294299 _startLatencyMetric = null ;
295300
301+ if ( _disposing )
302+ {
303+ // do not publish ready events when disposing
304+ return ;
305+ }
296306 _initMessage = initEvent . Message . WorkerInitResponse ;
297307 if ( _initMessage . Result . IsFailure ( out Exception exc ) )
298308 {
@@ -494,6 +504,10 @@ internal void Log(RpcEvent msg)
494504
495505 internal void HandleWorkerError ( Exception exc )
496506 {
507+ if ( _disposing )
508+ {
509+ return ;
510+ }
497511 LanguageWorkerProcessExitException langExc = exc as LanguageWorkerProcessExitException ;
498512 // The subscriber of WorkerErrorEvent is expected to Dispose() the errored channel
499513 if ( langExc != null && langExc . ExitCode == - 1 )
Original file line number Diff line number Diff line change @@ -37,9 +37,11 @@ internal void DisposeAndRemoveChannels()
3737 {
3838 foreach ( string channelId in _channels . Keys )
3939 {
40- _channels [ channelId ] . Dispose ( ) ;
40+ if ( _channels . TryRemove ( channelId , out ILanguageWorkerChannel channel ) )
41+ {
42+ channel ? . Dispose ( ) ;
43+ }
4144 }
42- _channels . Clear ( ) ;
4345 }
4446
4547 internal IEnumerable < ILanguageWorkerChannel > GetChannels ( )
You can’t perform that action at this time.
0 commit comments