Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't panic on unknown token_id in gRPC callbacks. #210

30 changes: 19 additions & 11 deletions src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,14 @@ impl Dispatcher {
}

fn on_grpc_receive_initial_metadata(&self, token_id: u32, headers: u32) {
let context_id = *self
.grpc_streams
.borrow_mut()
.get(&token_id)
.expect("invalid token_id");
let context_id = match self.grpc_streams.borrow_mut().get(&token_id) {
Some(id) => *id,
None => {
// TODO: change back to a panic once underlying issue is fixed.
trace!("on_grpc_receive_initial_metadata: invalid token_id");
return;
}
};

if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) {
self.active_id.set(context_id);
Expand Down Expand Up @@ -480,16 +483,21 @@ impl Dispatcher {
root.on_grpc_stream_message(token_id, response_size);
}
} else {
panic!("invalid token_id")
// TODO: change back to a panic once underlying issue is fixed.
trace!("on_grpc_receive_initial_metadata: invalid token_id");
return;
}
}

fn on_grpc_receive_trailing_metadata(&self, token_id: u32, trailers: u32) {
let context_id = *self
.grpc_streams
.borrow_mut()
.get(&token_id)
.expect("invalid token_id");
let context_id = match self.grpc_streams.borrow_mut().get(&token_id) {
Some(id) => *id,
None => {
// TODO: change back to a panic once underlying issue is fixed.
trace!("on_grpc_receive_trailing_metadata: invalid token_id");
return;
}
};

if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) {
self.active_id.set(context_id);
Expand Down