@@ -517,7 +517,8 @@ impl Dispatcher {
517
517
}
518
518
519
519
fn on_grpc_close ( & self , token_id : u32 , status_code : u32 ) {
520
- if let Some ( context_id) = self . grpc_callouts . borrow_mut ( ) . remove ( & token_id) {
520
+ let context_id = self . grpc_callouts . borrow_mut ( ) . remove ( & token_id) ;
521
+ if let Some ( context_id) = context_id {
521
522
if let Some ( http_stream) = self . http_streams . borrow_mut ( ) . get_mut ( & context_id) {
522
523
self . active_id . set ( context_id) ;
523
524
hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
@@ -531,23 +532,26 @@ impl Dispatcher {
531
532
hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
532
533
root. on_grpc_call_response ( token_id, status_code, 0 ) ;
533
534
}
534
- } else if let Some ( context_id) = self . grpc_streams . borrow_mut ( ) . remove ( & token_id) {
535
- if let Some ( http_stream) = self . http_streams . borrow_mut ( ) . get_mut ( & context_id) {
536
- self . active_id . set ( context_id) ;
537
- hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
538
- http_stream. on_grpc_stream_close ( token_id, status_code)
539
- } else if let Some ( stream) = self . streams . borrow_mut ( ) . get_mut ( & context_id) {
540
- self . active_id . set ( context_id) ;
541
- hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
542
- stream. on_grpc_stream_close ( token_id, status_code)
543
- } else if let Some ( root) = self . roots . borrow_mut ( ) . get_mut ( & context_id) {
544
- self . active_id . set ( context_id) ;
545
- hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
546
- root. on_grpc_stream_close ( token_id, status_code)
547
- }
548
535
} else {
549
- // TODO: change back to a panic once underlying issue is fixed.
550
- trace ! ( "on_grpc_close: invalid token_id, a non-connected stream has closed" ) ;
536
+ let context_id = self . grpc_streams . borrow_mut ( ) . remove ( & token_id) ;
537
+ if let Some ( context_id) = context_id {
538
+ if let Some ( http_stream) = self . http_streams . borrow_mut ( ) . get_mut ( & context_id) {
539
+ self . active_id . set ( context_id) ;
540
+ hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
541
+ http_stream. on_grpc_stream_close ( token_id, status_code)
542
+ } else if let Some ( stream) = self . streams . borrow_mut ( ) . get_mut ( & context_id) {
543
+ self . active_id . set ( context_id) ;
544
+ hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
545
+ stream. on_grpc_stream_close ( token_id, status_code)
546
+ } else if let Some ( root) = self . roots . borrow_mut ( ) . get_mut ( & context_id) {
547
+ self . active_id . set ( context_id) ;
548
+ hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
549
+ root. on_grpc_stream_close ( token_id, status_code)
550
+ }
551
+ } else {
552
+ // TODO: change back to a panic once underlying issue is fixed.
553
+ trace ! ( "on_grpc_close: invalid token_id, a non-connected stream has closed" ) ;
554
+ }
551
555
}
552
556
}
553
557
}
0 commit comments