diff --git a/packages/grpc-native-core/ext/channel.cc b/packages/grpc-native-core/ext/channel.cc index bd7a6392..825260e0 100644 --- a/packages/grpc-native-core/ext/channel.cc +++ b/packages/grpc-native-core/ext/channel.cc @@ -270,6 +270,10 @@ NAN_METHOD(Channel::GetTarget) { "getTarget can only be called on Channel objects"); } Channel *channel = ObjectWrap::Unwrap(info.This()); + if (channel->wrapped_channel == NULL) { + return Nan::ThrowError( + "Cannot call getTarget on a closed Channel"); + } info.GetReturnValue().Set( Nan::New(grpc_channel_get_target(channel->wrapped_channel)) .ToLocalChecked()); @@ -281,6 +285,10 @@ NAN_METHOD(Channel::GetConnectivityState) { "getConnectivityState can only be called on Channel objects"); } Channel *channel = ObjectWrap::Unwrap(info.This()); + if (channel->wrapped_channel == NULL) { + return Nan::ThrowError( + "Cannot call getConnectivityState on a closed Channel"); + } int try_to_connect = (int)info[0]->Equals(Nan::True()); info.GetReturnValue().Set(grpc_channel_check_connectivity_state( channel->wrapped_channel, try_to_connect)); @@ -303,12 +311,16 @@ NAN_METHOD(Channel::WatchConnectivityState) { return Nan::ThrowTypeError( "watchConnectivityState's third argument must be a callback"); } + Channel *channel = ObjectWrap::Unwrap(info.This()); + if (channel->wrapped_channel == NULL) { + return Nan::ThrowError( + "Cannot call watchConnectivityState on a closed Channel"); + } grpc_connectivity_state last_state = static_cast( Nan::To(info[0]).FromJust()); double deadline = Nan::To(info[1]).FromJust(); Local callback_func = info[2].As(); Nan::Callback *callback = new Callback(callback_func); - Channel *channel = ObjectWrap::Unwrap(info.This()); unique_ptr ops(new OpVec()); grpc_channel_watch_connectivity_state( channel->wrapped_channel, last_state, MillisecondsToTimespec(deadline),