From 474f53b13835b5f42e0ef86947497eba28b45441 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 14 Sep 2015 13:53:07 -0700 Subject: [PATCH 1/4] Fixed Op destructors not being called --- src/node/ext/call.cc | 5 ++++- src/node/ext/call.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index 560869e6fa4..49b306202bd 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -172,6 +172,9 @@ Handle Op::GetOpType() const { return NanEscapeScope(NanNew(GetTypeString())); } +Op::~Op() { +} + class SendMetadataOp : public Op { public: Handle GetNodeValue() const { @@ -325,7 +328,7 @@ class ReadMessageOp : public Op { } ~ReadMessageOp() { if (recv_message != NULL) { - gpr_free(recv_message); + grpc_byte_buffer_destroy(recv_message); } } Handle GetNodeValue() const { diff --git a/src/node/ext/call.h b/src/node/ext/call.h index 89f81dcf4dc..a01f03489e7 100644 --- a/src/node/ext/call.h +++ b/src/node/ext/call.h @@ -88,6 +88,7 @@ struct Resources { class Op { public: + virtual ~Op(); virtual v8::Handle GetNodeValue() const = 0; virtual bool ParseOp(v8::Handle value, grpc_op *out, shared_ptr resources) = 0; @@ -98,7 +99,6 @@ class Op { }; typedef std::vector> OpVec; - struct tag { tag(NanCallback *callback, OpVec *ops, shared_ptr resources); From 640325e65eb52c213be8349b7f4400cf4cc7f62e Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 14 Sep 2015 14:16:04 -0700 Subject: [PATCH 2/4] Fixed memory leak in Buffer construction --- src/node/ext/byte_buffer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/ext/byte_buffer.cc b/src/node/ext/byte_buffer.cc index 7eff11c2b34..fe7735d4294 100644 --- a/src/node/ext/byte_buffer.cc +++ b/src/node/ext/byte_buffer.cc @@ -77,7 +77,7 @@ Handle ByteBufferToBuffer(grpc_byte_buffer *buffer) { memcpy(result + offset, GPR_SLICE_START_PTR(next), GPR_SLICE_LENGTH(next)); offset += GPR_SLICE_LENGTH(next); } - return NanEscapeScope(MakeFastBuffer(NanNewBufferHandle(result, length))); + return NanEscapeScope(MakeFastBuffer(NanBufferUse(result, length))); } Handle MakeFastBuffer(Handle slowBuffer) { From a59ee9a30792b8d5bb5e42b481c18f6222a67577 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 15 Sep 2015 09:23:55 -0700 Subject: [PATCH 3/4] Fixed a couple of incorrect "this" references in Node library --- src/node/src/server.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/node/src/server.js b/src/node/src/server.js index b6f162adf85..70b4a9d80e3 100644 --- a/src/node/src/server.js +++ b/src/node/src/server.js @@ -276,6 +276,7 @@ function ServerWritableStream(call, serialize) { function _write(chunk, encoding, callback) { /* jshint validthis: true */ var batch = {}; + var self = this; if (!this.call.metadataSent) { batch[grpc.opType.SEND_INITIAL_METADATA] = (new Metadata())._getCoreRepresentation(); @@ -290,7 +291,7 @@ function _write(chunk, encoding, callback) { batch[grpc.opType.SEND_MESSAGE] = message; this.call.startBatch(batch, function(err, value) { if (err) { - this.emit('error', err); + self.emit('error', err); return; } callback(); @@ -305,6 +306,7 @@ ServerWritableStream.prototype._write = _write; */ function sendMetadata(responseMetadata) { /* jshint validthis: true */ + var self = this; if (!this.call.metadataSent) { this.call.metadataSent = true; var batch = []; @@ -312,7 +314,7 @@ function sendMetadata(responseMetadata) { responseMetadata._getCoreRepresentation(); this.call.startBatch(batch, function(err) { if (err) { - this.emit('error', err); + self.emit('error', err); return; } }); From 156a7b6e0f657ea6a1df1cf6574003920f0da714 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 16 Sep 2015 09:55:27 -0700 Subject: [PATCH 4/4] Don't do .Wait() in async context. Failing to use await can result in deadlock. This is likely to be the cause of shutdown hangs in #3347. --- src/csharp/Grpc.IntegrationTesting/InteropClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs index 0884c6ea60a..616093d4aeb 100644 --- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs +++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs @@ -131,7 +131,7 @@ namespace Grpc.IntegrationTesting var channel = new Channel(options.ServerHost, options.ServerPort, credentials, channelOptions); TestService.TestServiceClient client = new TestService.TestServiceClient(channel); await RunTestCaseAsync(client, options); - channel.ShutdownAsync().Wait(); + await channel.ShutdownAsync(); } private async Task RunTestCaseAsync(TestService.TestServiceClient client, ClientOptions options)