aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar murgatroid99 <mlumish@google.com>2017-06-15 17:48:42 -0700
committerGravatar murgatroid99 <mlumish@google.com>2017-06-15 17:48:42 -0700
commitd5b0455110b834c7fa102a0338882a4f98d31ae8 (patch)
treedcc9789852f362a5986709587475aee4822cd350 /src
parentfb5ad8d2b9b5fc541a3a85703783fe8e7e4ee91b (diff)
parent2f850801235580217bb74c5911686bce0374dcad (diff)
Merge remote-tracking branch 'upstream/v1.4.x' into upmerge_1.4.x
Diffstat (limited to 'src')
-rw-r--r--src/csharp/Grpc.Core.Tests/ServerTest.cs16
-rw-r--r--src/csharp/Grpc.Core/Server.cs21
-rw-r--r--src/csharp/ext/grpc_csharp_ext.c14
-rw-r--r--src/node/src/grpc_extension.js7
-rw-r--r--src/node/test/surface_test.js47
-rw-r--r--src/php/ext/grpc/version.h2
6 files changed, 102 insertions, 5 deletions
diff --git a/src/csharp/Grpc.Core.Tests/ServerTest.cs b/src/csharp/Grpc.Core.Tests/ServerTest.cs
index f6343f2a13..884414792d 100644
--- a/src/csharp/Grpc.Core.Tests/ServerTest.cs
+++ b/src/csharp/Grpc.Core.Tests/ServerTest.cs
@@ -17,6 +17,7 @@
#endregion
using System;
+using System.IO;
using System.Linq;
using Grpc.Core;
using Grpc.Core.Internal;
@@ -66,6 +67,21 @@ namespace Grpc.Core.Tests
}
[Test]
+ public void StartThrowsWithUnboundPorts()
+ {
+ int twiceBoundPort = 9999;
+ Server server = new Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) })
+ {
+ Ports = {
+ new ServerPort("localhost", twiceBoundPort, ServerCredentials.Insecure),
+ new ServerPort("localhost", twiceBoundPort, ServerCredentials.Insecure)
+ }
+ };
+ Assert.Throws(typeof(IOException), () => server.Start());
+ server.ShutdownAsync().Wait();
+ }
+
+ [Test]
public void CannotModifyAfterStarted()
{
Server server = new Server
diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs
index 462713e6bb..77ad876bdf 100644
--- a/src/csharp/Grpc.Core/Server.cs
+++ b/src/csharp/Grpc.Core/Server.cs
@@ -19,6 +19,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Grpc.Core.Internal;
@@ -140,6 +141,7 @@ namespace Grpc.Core
/// <summary>
/// Starts the server.
+ /// Throws <c>IOException</c> if not successful.
/// </summary>
public void Start()
{
@@ -148,7 +150,8 @@ namespace Grpc.Core
GrpcPreconditions.CheckState(!startRequested);
GrpcPreconditions.CheckState(!shutdownRequested);
startRequested = true;
-
+
+ CheckPortsBoundSuccessfully();
handle.Start();
for (int i = 0; i < requestCallTokensPerCq; i++)
@@ -301,6 +304,22 @@ namespace Grpc.Core
}
}
+ /// <summary>
+ /// Checks that all ports have been bound successfully.
+ /// </summary>
+ private void CheckPortsBoundSuccessfully()
+ {
+ lock (myLock)
+ {
+ var unboundPort = ports.FirstOrDefault(port => port.BoundPort == 0);
+ if (unboundPort != null)
+ {
+ throw new IOException(
+ string.Format("Failed to bind port \"{0}:{1}\"", unboundPort.Host, unboundPort.Port));
+ }
+ }
+ }
+
private void DisposeHandle()
{
var activeCallCount = activeCallCounter.Count;
diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c
index f5c0030309..aebce364c5 100644
--- a/src/csharp/ext/grpc_csharp_ext.c
+++ b/src/csharp/ext/grpc_csharp_ext.c
@@ -398,8 +398,14 @@ GPR_EXPORT grpc_call *GPR_CALLTYPE grpcsharp_channel_create_call(
host_slice = grpc_slice_from_copied_string(host);
host_slice_ptr = &host_slice;
}
- return grpc_channel_create_call(channel, parent_call, propagation_mask, cq,
- method_slice, host_slice_ptr, deadline, NULL);
+ grpc_call *ret =
+ grpc_channel_create_call(channel, parent_call, propagation_mask, cq,
+ method_slice, host_slice_ptr, deadline, NULL);
+ grpc_slice_unref(method_slice);
+ if (host != NULL) {
+ grpc_slice_unref(host_slice);
+ }
+ return ret;
}
GPR_EXPORT grpc_connectivity_state GPR_CALLTYPE
@@ -790,7 +796,9 @@ GPR_EXPORT grpc_call_error GPR_CALLTYPE grpcsharp_call_send_status_from_server(
ops[nops].reserved = NULL;
nops++;
}
- return grpcsharp_call_start_batch(call, ops, nops, ctx, NULL);
+ grpc_call_error ret = grpcsharp_call_start_batch(call, ops, nops, ctx, NULL);
+ grpc_slice_unref(status_details_slice);
+ return ret;
}
GPR_EXPORT grpc_call_error GPR_CALLTYPE
diff --git a/src/node/src/grpc_extension.js b/src/node/src/grpc_extension.js
index c13bf819de..af43eacad2 100644
--- a/src/node/src/grpc_extension.js
+++ b/src/node/src/grpc_extension.js
@@ -16,6 +16,13 @@
*
*/
+/**
+ * @module
+ * @private
+ */
+
+'use strict';
+
var binary = require('node-pre-gyp/lib/pre-binding');
var path = require('path');
var binding_path =
diff --git a/src/node/test/surface_test.js b/src/node/test/surface_test.js
index 8c750ea484..d58d18057e 100644
--- a/src/node/test/surface_test.js
+++ b/src/node/test/surface_test.js
@@ -1363,3 +1363,50 @@ describe('Cancelling surface client', function() {
call.cancel();
});
});
+describe('Client reconnect', function() {
+ var server;
+ var Client;
+ var client;
+ var port;
+ beforeEach(function() {
+ var test_proto = ProtoBuf.loadProtoFile(__dirname + '/echo_service.proto');
+ var echo_service = test_proto.lookup('EchoService');
+ Client = grpc.loadObject(echo_service);
+ server = new grpc.Server();
+ server.addService(Client.service, {
+ echo: function(call, callback) {
+ callback(null, call.request);
+ }
+ });
+ port = server.bind('localhost:0', server_insecure_creds);
+ client = new Client('localhost:' + port, grpc.credentials.createInsecure());
+ server.start();
+ });
+ afterEach(function() {
+ server.forceShutdown();
+ });
+ it('should reconnect after server restart', function(done) {
+ client.echo({value: 'test value', value2: 3}, function(error, response) {
+ assert.ifError(error);
+ assert.deepEqual(response, {value: 'test value', value2: 3});
+ server.tryShutdown(function() {
+ server = new grpc.Server();
+ server.addService(Client.service, {
+ echo: function(call, callback) {
+ callback(null, call.request);
+ }
+ });
+ server.bind('localhost:' + port, server_insecure_creds);
+ server.start();
+ client.echo(undefined, function(error, response) {
+ if (error) {
+ console.log(error);
+ }
+ assert.ifError(error);
+ assert.deepEqual(response, {value: '', value2: 0});
+ done();
+ });
+ });
+ });
+ });
+});
diff --git a/src/php/ext/grpc/version.h b/src/php/ext/grpc/version.h
index 2e8f0f2b64..744028b2ca 100644
--- a/src/php/ext/grpc/version.h
+++ b/src/php/ext/grpc/version.h
@@ -20,6 +20,6 @@
#ifndef VERSION_H
#define VERSION_H
-#define PHP_GRPC_VERSION "1.5.0"
+#define PHP_GRPC_VERSION "1.5.0dev"
#endif /* VERSION_H */