diff --git a/ext/call.cc b/ext/call.cc index e9179173..71e69040 100644 --- a/ext/call.cc +++ b/ext/call.cc @@ -383,7 +383,10 @@ class ClientStatusOp : public Op { public: ClientStatusOp() { grpc_metadata_array_init(&metadata_array); } - ~ClientStatusOp() { grpc_metadata_array_destroy(&metadata_array); } + ~ClientStatusOp() { + grpc_metadata_array_destroy(&metadata_array); + grpc_slice_unref(status_details); + } bool ParseOp(Local value, grpc_op *out) { out->data.recv_status_on_client.trailing_metadata = &metadata_array; diff --git a/src/client.js b/src/client.js index 6eb5f99c..edc51b78 100644 --- a/src/client.js +++ b/src/client.js @@ -137,6 +137,7 @@ function _write(chunk, encoding, callback) { /* Once a write fails, just call the callback immediately to let the caller flush any pending writes. */ setImmediate(callback); + return; } try { message = this.serialize(chunk); @@ -149,6 +150,7 @@ function _write(chunk, encoding, callback) { this.call.cancelWithStatus(constants.status.INTERNAL, 'Serialization failure'); callback(e); + return; } if (_.isFinite(encoding)) { /* Attach the encoding if it is a finite number. This is the closest we diff --git a/src/protobuf_js_6_common.js b/src/protobuf_js_6_common.js index f1e4914f..0f072516 100644 --- a/src/protobuf_js_6_common.js +++ b/src/protobuf_js_6_common.js @@ -49,7 +49,7 @@ exports.deserializeCls = function deserializeCls(cls, options) { * @return {cls} The resulting object */ return function deserialize(arg_buf) { - return cls.decode(arg_buf).toObject(conversion_options); + return cls.toObject(cls.decode(arg_buf), conversion_options); }; }; diff --git a/test/surface_test.js b/test/surface_test.js index d58d1805..0b0b393e 100644 --- a/test/surface_test.js +++ b/test/surface_test.js @@ -1398,13 +1398,25 @@ describe('Client reconnect', function() { }); server.bind('localhost:' + port, server_insecure_creds); server.start(); - client.echo(undefined, function(error, response) { - if (error) { - console.log(error); - } + + /* We create a new client, that will not throw an error if the server + * is not immediately available. Instead, it will wait for the server + * to be available, then the call will complete. Once this happens, the + * original client should be able to make a new call and connect to the + * restarted server without having the call fail due to connection + * errors. */ + var client2 = new Client('localhost:' + port, + grpc.credentials.createInsecure()); + client2.echo({value: 'test', value2: 3}, function(error, response) { assert.ifError(error); - assert.deepEqual(response, {value: '', value2: 0}); - done(); + client.echo(undefined, function(error, response) { + if (error) { + console.log(error); + } + assert.ifError(error); + assert.deepEqual(response, {value: '', value2: 0}); + done(); + }); }); }); });