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
263
263
264
264
protected virtual void Dispose ( bool disposing )
265
265
{
266
- if ( ! _disposed )
266
+ if ( ! _disposed && disposing )
267
267
{
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 ( ) ;
275
272
_disposed = true ;
276
273
}
277
274
}
Original file line number Diff line number Diff line change @@ -284,6 +284,11 @@ internal void SendWorkerInitRequest(RpcEvent startEvent)
284
284
285
285
internal void PublishWorkerProcessReadyEvent ( FunctionEnvironmentReloadResponse res )
286
286
{
287
+ if ( _disposing )
288
+ {
289
+ // do not publish ready events when disposing
290
+ return ;
291
+ }
287
292
WorkerProcessReadyEvent wpEvent = new WorkerProcessReadyEvent ( _workerId , _workerConfig . Language ) ;
288
293
_eventManager . Publish ( wpEvent ) ;
289
294
}
@@ -293,6 +298,11 @@ internal void PublishRpcChannelReadyEvent(RpcEvent initEvent)
293
298
_startLatencyMetric ? . Dispose ( ) ;
294
299
_startLatencyMetric = null ;
295
300
301
+ if ( _disposing )
302
+ {
303
+ // do not publish ready events when disposing
304
+ return ;
305
+ }
296
306
_initMessage = initEvent . Message . WorkerInitResponse ;
297
307
if ( _initMessage . Result . IsFailure ( out Exception exc ) )
298
308
{
@@ -494,6 +504,10 @@ internal void Log(RpcEvent msg)
494
504
495
505
internal void HandleWorkerError ( Exception exc )
496
506
{
507
+ if ( _disposing )
508
+ {
509
+ return ;
510
+ }
497
511
LanguageWorkerProcessExitException langExc = exc as LanguageWorkerProcessExitException ;
498
512
// The subscriber of WorkerErrorEvent is expected to Dispose() the errored channel
499
513
if ( langExc != null && langExc . ExitCode == - 1 )
Original file line number Diff line number Diff line change @@ -37,9 +37,11 @@ internal void DisposeAndRemoveChannels()
37
37
{
38
38
foreach ( string channelId in _channels . Keys )
39
39
{
40
- _channels [ channelId ] . Dispose ( ) ;
40
+ if ( _channels . TryRemove ( channelId , out ILanguageWorkerChannel channel ) )
41
+ {
42
+ channel ? . Dispose ( ) ;
43
+ }
41
44
}
42
- _channels . Clear ( ) ;
43
45
}
44
46
45
47
internal IEnumerable < ILanguageWorkerChannel > GetChannels ( )
You can’t perform that action at this time.
0 commit comments