From b52a4bc4c98fea0801a3027239297a7e69bece32 Mon Sep 17 00:00:00 2001 From: Julien Boeuf Date: Thu, 9 Jul 2015 10:16:12 -0700 Subject: [PATCH 01/34] Upgrading to OpenSSL 1.0.2d --- third_party/openssl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/openssl b/third_party/openssl index 3df69d3aefd..33dd0832064 160000 --- a/third_party/openssl +++ b/third_party/openssl @@ -1 +1 @@ -Subproject commit 3df69d3aefde7671053d4e3c242b228e5d79c83f +Subproject commit 33dd08320648ac71d7d9d732be774ed3818dccc5 From a4b7b19d9ca5ba6661fd25585052b18036657b6c Mon Sep 17 00:00:00 2001 From: Julien Boeuf Date: Thu, 9 Jul 2015 11:04:25 -0700 Subject: [PATCH 02/34] Upgrading sanity test as well. --- tools/run_tests/run_sanity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/run_sanity.sh b/tools/run_tests/run_sanity.sh index ebb09d94696..2b33ba852d9 100755 --- a/tools/run_tests/run_sanity.sh +++ b/tools/run_tests/run_sanity.sh @@ -44,7 +44,7 @@ git submodule > $submodules diff -u $submodules - << EOF 05b155ff59114735ec8cd089f669c4c3d8f59029 third_party/gflags (v2.1.0-45-g05b155f) - 3df69d3aefde7671053d4e3c242b228e5d79c83f third_party/openssl (OpenSSL_1_0_2a) + 33dd08320648ac71d7d9d732be774ed3818dccc5 third_party/openssl (OpenSSL_1_0_2d) 3e2c8a5dd79481e1d36572cdf65be93514ba6581 third_party/protobuf (v3.0.0-alpha-1-1048-g3e2c8a5) 50893291621658f355bc5b4d450a8d06a563053d third_party/zlib (v1.2.8) EOF From a7c162c17c6d126ef3466ab3f2d199ceea76b1f7 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 24 Jul 2015 20:21:51 +0200 Subject: [PATCH 03/34] The code evolved enough so that we now have tests that directly depend on OpenSSL. Reflecting that in the Makefile so that we don't race against the system when building. --- Makefile | 38 +++++++++++++++++++++++++++++++++++++ templates/Makefile.template | 8 ++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 083c01aaacb..0b7cef86f33 100644 --- a/Makefile +++ b/Makefile @@ -17347,6 +17347,8 @@ ifneq ($(OPENSSL_DEP),) # This is to ensure the embedded OpenSSL is built beforehand, properly # installing headers to their final destination on the drive. We need this # otherwise parallel compilation will fail if a source is compiled first. +examples/pubsub/publisher.cc: $(OPENSSL_DEP) +examples/pubsub/subscriber.cc: $(OPENSSL_DEP) src/core/httpcli/format_request.c: $(OPENSSL_DEP) src/core/httpcli/httpcli.c: $(OPENSSL_DEP) src/core/httpcli/httpcli_security_connector.c: $(OPENSSL_DEP) @@ -17371,6 +17373,42 @@ src/core/surface/secure_channel_create.c: $(OPENSSL_DEP) src/core/tsi/fake_transport_security.c: $(OPENSSL_DEP) src/core/tsi/ssl_transport_security.c: $(OPENSSL_DEP) src/core/tsi/transport_security.c: $(OPENSSL_DEP) +src/cpp/client/secure_channel_arguments.cc: $(OPENSSL_DEP) +src/cpp/client/secure_credentials.cc: $(OPENSSL_DEP) +src/cpp/common/auth_property_iterator.cc: $(OPENSSL_DEP) +src/cpp/common/secure_auth_context.cc: $(OPENSSL_DEP) +src/cpp/common/secure_create_auth_context.cc: $(OPENSSL_DEP) +src/cpp/server/secure_server_credentials.cc: $(OPENSSL_DEP) +src/csharp/ext/grpc_csharp_ext.c: $(OPENSSL_DEP) +test/core/bad_client/bad_client.c: $(OPENSSL_DEP) +test/core/end2end/data/server1_cert.c: $(OPENSSL_DEP) +test/core/end2end/data/server1_key.c: $(OPENSSL_DEP) +test/core/end2end/data/test_root_cert.c: $(OPENSSL_DEP) +test/core/end2end/fixtures/chttp2_fake_security.c: $(OPENSSL_DEP) +test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c: $(OPENSSL_DEP) +test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_poll.c: $(OPENSSL_DEP) +test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c: $(OPENSSL_DEP) +test/core/end2end/tests/request_response_with_payload_and_call_creds.c: $(OPENSSL_DEP) +test/cpp/interop/client.cc: $(OPENSSL_DEP) +test/cpp/interop/client_helper.cc: $(OPENSSL_DEP) +test/cpp/interop/interop_client.cc: $(OPENSSL_DEP) +test/cpp/interop/server.cc: $(OPENSSL_DEP) +test/cpp/interop/server_helper.cc: $(OPENSSL_DEP) +test/cpp/qps/client_async.cc: $(OPENSSL_DEP) +test/cpp/qps/client_sync.cc: $(OPENSSL_DEP) +test/cpp/qps/driver.cc: $(OPENSSL_DEP) +test/cpp/qps/perf_db_client.cc: $(OPENSSL_DEP) +test/cpp/qps/qps_worker.cc: $(OPENSSL_DEP) +test/cpp/qps/report.cc: $(OPENSSL_DEP) +test/cpp/qps/server_async.cc: $(OPENSSL_DEP) +test/cpp/qps/server_sync.cc: $(OPENSSL_DEP) +test/cpp/qps/timer.cc: $(OPENSSL_DEP) +test/cpp/util/benchmark_config.cc: $(OPENSSL_DEP) +test/cpp/util/cli_call.cc: $(OPENSSL_DEP) +test/cpp/util/create_test_channel.cc: $(OPENSSL_DEP) +test/cpp/util/fake_credentials.cc: $(OPENSSL_DEP) +test/cpp/util/subprocess.cc: $(OPENSSL_DEP) +test/cpp/util/test_config.cc: $(OPENSSL_DEP) endif .PHONY: all strip tools dep_error openssl_dep_error openssl_dep_message git_update stop buildtests buildtests_c buildtests_cxx test test_c test_cxx install install_c install_cxx install-headers install-headers_c install-headers_cxx install-shared install-shared_c install-shared_cxx install-static install-static_c install-static_cxx strip strip-shared strip-static strip_c strip-shared_c strip-static_c strip_cxx strip-shared_cxx strip-static_cxx dep_c dep_cxx bins_dep_c bins_dep_cxx clean diff --git a/templates/Makefile.template b/templates/Makefile.template index 1e46db11dce..6530ea5eb23 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -1468,10 +1468,14 @@ endif mingw_libs = mingw_libs + ' -l' + dep + '-imp' mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '.$(SHARED_EXT)' - if lib.get('secure', 'check') == 'yes': + security = lib.get('secure', 'check') + if security == 'yes': common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)' + + if security in ['yes', 'check']: for src in lib.src: - sources_that_need_openssl.add(src) + if not proto_re.match(src): + sources_that_need_openssl.add(src) else: for src in lib.src: sources_that_don_t_need_openssl.add(src) From 910f3de184453d0ecc1e5916cb38dbd65fa229cb Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Fri, 31 Jul 2015 15:37:20 -0700 Subject: [PATCH 04/34] Addenda to tools readme --- tools/README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tools/README.md b/tools/README.md index 3daf73228c1..be7d84b3738 100644 --- a/tools/README.md +++ b/tools/README.md @@ -1,11 +1,17 @@ -buildgen: contains the template renderer for our build system. +buildgen: template renderer for our build system. -distpackages: contains script to generate debian packages. +distpackages: script to generate debian packages. -dockerfile: contains all of the docker files to test gRPC. +distrib: scripts to distribute language-specific packages. -gce_setup: contains boilerplate for running the docker files under GCE. +dockerfile: Docker files to test gRPC. -jenkins: support for running tests on Jenkins +doxygen: gRPC C/C++ documentation generation via Doxygen. -run_tests: contains python scripts to properly run the tests in parallel. +gce_setup: boilerplate to run the Docker files under GCE. + +jenkins: support for running tests on Jenkins. + +profile_analyzer: pretty printer for gRPC profiling data. + +run_tests: scripts to run gRPC tests in parallel. From d556da9f2859a7d0a77f2bb8b81362175252350f Mon Sep 17 00:00:00 2001 From: yang-g Date: Fri, 31 Jul 2015 15:59:04 -0700 Subject: [PATCH 05/34] Pass NULL as host by default. Use context.authority() or channel.SslNameOverride() when set. --- src/cpp/client/channel.cc | 12 ++++++++---- src/cpp/client/channel.h | 5 +++-- src/cpp/client/create_channel.cc | 4 ++-- src/cpp/client/insecure_credentials.cc | 2 +- src/cpp/client/secure_credentials.cc | 3 +-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/cpp/client/channel.cc b/src/cpp/client/channel.cc index 5df81e641ef..ee143d68a0f 100644 --- a/src/cpp/client/channel.cc +++ b/src/cpp/client/channel.cc @@ -51,13 +51,16 @@ namespace grpc { -Channel::Channel(const grpc::string& target, grpc_channel* channel) - : target_(target), c_channel_(channel) {} +Channel::Channel(grpc_channel* channel) : c_channel_(channel) {} + +Channel::Channel(const grpc::string& host, grpc_channel* channel) + : host_(host), c_channel_(channel) {} Channel::~Channel() { grpc_channel_destroy(c_channel_); } Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, CompletionQueue* cq) { + const char* host_str = host_.empty() ? NULL : host_.c_str(); auto c_call = method.channel_tag() && context->authority().empty() ? grpc_channel_create_registered_call(c_channel_, cq->cq(), @@ -65,7 +68,7 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, context->raw_deadline()) : grpc_channel_create_call(c_channel_, cq->cq(), method.name(), context->authority().empty() - ? target_.c_str() + ? host_str : context->authority().c_str(), context->raw_deadline()); grpc_census_call_set_context(c_call, context->census_context()); @@ -86,7 +89,8 @@ void Channel::PerformOpsOnCall(CallOpSetInterface* ops, Call* call) { } void* Channel::RegisterMethod(const char* method) { - return grpc_channel_register_call(c_channel_, method, target_.c_str()); + return grpc_channel_register_call(c_channel_, method, + host_.empty() ? NULL : host_.c_str()); } } // namespace grpc diff --git a/src/cpp/client/channel.h b/src/cpp/client/channel.h index 9108713c589..8660146856c 100644 --- a/src/cpp/client/channel.h +++ b/src/cpp/client/channel.h @@ -52,7 +52,8 @@ class StreamContextInterface; class Channel GRPC_FINAL : public GrpcLibrary, public ChannelInterface { public: - Channel(const grpc::string& target, grpc_channel* c_channel); + explicit Channel(grpc_channel* c_channel); + Channel(const grpc::string& host, grpc_channel* c_channel); ~Channel() GRPC_OVERRIDE; virtual void* RegisterMethod(const char* method) GRPC_OVERRIDE; @@ -62,7 +63,7 @@ class Channel GRPC_FINAL : public GrpcLibrary, public ChannelInterface { Call* call) GRPC_OVERRIDE; private: - const grpc::string target_; + const grpc::string host_; grpc_channel* const c_channel_; // owned }; diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc index dbe2694a78d..21d01b739d6 100644 --- a/src/cpp/client/create_channel.cc +++ b/src/cpp/client/create_channel.cc @@ -51,7 +51,7 @@ std::shared_ptr CreateChannel( cp_args.SetString(GRPC_ARG_PRIMARY_USER_AGENT_STRING, user_agent_prefix.str()); return creds ? creds->CreateChannel(target, cp_args) - : std::shared_ptr(new Channel( - target, grpc_lame_client_channel_create(NULL))); + : std::shared_ptr( + new Channel(grpc_lame_client_channel_create(NULL))); } } // namespace grpc diff --git a/src/cpp/client/insecure_credentials.cc b/src/cpp/client/insecure_credentials.cc index e802fa8034e..d8dcaa1436a 100644 --- a/src/cpp/client/insecure_credentials.cc +++ b/src/cpp/client/insecure_credentials.cc @@ -49,7 +49,7 @@ class InsecureCredentialsImpl GRPC_FINAL : public Credentials { grpc_channel_args channel_args; args.SetChannelArgs(&channel_args); return std::shared_ptr(new Channel( - target, grpc_insecure_channel_create(target.c_str(), &channel_args))); + grpc_insecure_channel_create(target.c_str(), &channel_args))); } // InsecureCredentials should not be applied to a call. diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index abf0cb387e3..2d6114e06b8 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -44,8 +44,7 @@ std::shared_ptr SecureCredentials::CreateChannel( grpc_channel_args channel_args; args.SetChannelArgs(&channel_args); return std::shared_ptr(new Channel( - args.GetSslTargetNameOverride().empty() ? target - : args.GetSslTargetNameOverride(), + args.GetSslTargetNameOverride(), grpc_secure_channel_create(c_creds_, target.c_str(), &channel_args))); } From dde9071f9b46ce2cd59040e75e81a6ecc7839ab8 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Fri, 31 Jul 2015 23:24:45 +0000 Subject: [PATCH 06/34] Affirm metadata transmission in a common function This introduces grpc_test.test_common for gRPC-specific test code and fixes issue 2570. --- .../grpc_test/_links/_transmission_test.py | 12 ++-- .../grpcio_test/grpc_test/test_common.py | 71 +++++++++++++++++++ 2 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 src/python/grpcio_test/grpc_test/test_common.py diff --git a/src/python/grpcio_test/grpc_test/_links/_transmission_test.py b/src/python/grpcio_test/grpc_test/_links/_transmission_test.py index 0531fa1d335..9cdc9620f0a 100644 --- a/src/python/grpcio_test/grpc_test/_links/_transmission_test.py +++ b/src/python/grpcio_test/grpc_test/_links/_transmission_test.py @@ -35,6 +35,7 @@ from grpc._adapter import _intermediary_low from grpc._links import invocation from grpc._links import service from grpc.framework.interfaces.links import links +from grpc_test import test_common from grpc_test._links import _proto_scenarios from grpc_test.framework.common import test_constants from grpc_test.framework.interfaces.links import test_cases @@ -94,12 +95,11 @@ class TransmissionTest(test_cases.TransmissionTest, unittest.TestCase): return _intermediary_low.Code.OK, 'An exuberant test "details" message!' def assertMetadataTransmitted(self, original_metadata, transmitted_metadata): - # we need to filter out any additional metadata added in transmitted_metadata - # since implementations are allowed to add to what is sent (in any position) - keys, _ = zip(*original_metadata) - self.assertSequenceEqual( - original_metadata, - [x for x in transmitted_metadata if x[0] in keys]) + self.assertTrue( + test_common.metadata_transmitted( + original_metadata, transmitted_metadata), + '%s erroneously transmitted as %s' % ( + original_metadata, transmitted_metadata)) class RoundTripTest(unittest.TestCase): diff --git a/src/python/grpcio_test/grpc_test/test_common.py b/src/python/grpcio_test/grpc_test/test_common.py new file mode 100644 index 00000000000..f8e1f1e43ff --- /dev/null +++ b/src/python/grpcio_test/grpc_test/test_common.py @@ -0,0 +1,71 @@ +# Copyright 2015, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +"""Common code used throughout tests of gRPC.""" + +import collections + + +def metadata_transmitted(original_metadata, transmitted_metadata): + """Judges whether or not metadata was acceptably transmitted. + + gRPC is allowed to insert key-value pairs into the metadata values given by + applications and to reorder key-value pairs with different keys but it is not + allowed to alter existing key-value pairs or to reorder key-value pairs with + the same key. + + Args: + original_metadata: A metadata value used in a test of gRPC. + transmitted_metadata: A metadata value corresponding to original_metadata + after having been transmitted via gRPC. + + Returns: + A boolean indicating whether transmitted_metadata accurately reflects + original_metadata after having been transmitted via gRPC. + """ + original = collections.defaultdict(list) + for key, value in original_metadata: + original[key].append(value) + transmitted = collections.defaultdict(list) + for key, value in transmitted_metadata: + transmitted[key].append(value) + + for key, values in original.iteritems(): + transmitted_values = transmitted[key] + transmitted_iterator = iter(transmitted_values) + try: + for value in values: + while True: + transmitted_value = next(transmitted_iterator) + if value == transmitted_value: + break + except StopIteration: + return False + else: + return True From 2f04c6e25849cc29e3427b37a2e3395c5d1f1a08 Mon Sep 17 00:00:00 2001 From: yang-g Date: Fri, 31 Jul 2015 22:02:22 -0700 Subject: [PATCH 07/34] check before unref, this will fail in BadCreds test --- src/core/surface/channel.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/surface/channel.c b/src/core/surface/channel.c index 81f673f856e..688a586e189 100644 --- a/src/core/surface/channel.c +++ b/src/core/surface/channel.c @@ -229,7 +229,9 @@ static void destroy_channel(void *p, int ok) { registered_call *rc = channel->registered_calls; channel->registered_calls = rc->next; GRPC_MDELEM_UNREF(rc->path); - GRPC_MDELEM_UNREF(rc->authority); + if (rc->authority) { + GRPC_MDELEM_UNREF(rc->authority); + } gpr_free(rc); } grpc_mdctx_unref(channel->metadata_context); From 940d555a6380af61e44efd6701928fe51d23d9fa Mon Sep 17 00:00:00 2001 From: yang-g Date: Fri, 31 Jul 2015 22:11:41 -0700 Subject: [PATCH 08/34] fix generic_end2end_test --- test/cpp/end2end/generic_end2end_test.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc index 4951c82b9aa..b53c32144b1 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -100,11 +100,11 @@ std::unique_ptr SerializeToByteBuffer( class GenericEnd2endTest : public ::testing::Test { protected: - GenericEnd2endTest() : generic_service_("*") {} + GenericEnd2endTest() : generic_service_("*"), server_host_("localhost") {} void SetUp() GRPC_OVERRIDE { int port = grpc_pick_unused_port_or_die(); - server_address_ << "localhost:" << port; + server_address_ << server_host_ << ":" << port; // Setup server ServerBuilder builder; builder.AddListeningPort(server_address_.str(), InsecureServerCredentials()); @@ -165,7 +165,7 @@ class GenericEnd2endTest : public ::testing::Test { srv_cq_.get(), tag(4)); verify_ok(srv_cq_.get(), 4, true); - EXPECT_EQ(server_address_.str(), srv_ctx.host()); + EXPECT_EQ(server_host_, srv_ctx.host()); EXPECT_EQ(kMethodName, srv_ctx.method()); ByteBuffer recv_buffer; stream.Read(&recv_buffer, tag(5)); @@ -200,6 +200,7 @@ class GenericEnd2endTest : public ::testing::Test { std::unique_ptr generic_stub_; std::unique_ptr server_; AsyncGenericService generic_service_; + const grpc::string server_host_; std::ostringstream server_address_; }; @@ -237,7 +238,7 @@ TEST_F(GenericEnd2endTest, SimpleBidiStreaming) { srv_cq_.get(), tag(2)); verify_ok(srv_cq_.get(), 2, true); - EXPECT_EQ(server_address_.str(), srv_ctx.host()); + EXPECT_EQ(server_host_, srv_ctx.host()); EXPECT_EQ(kMethodName, srv_ctx.method()); std::unique_ptr send_buffer = From 725835abf9127e71ccc7bba502dbb4e9fcc5343a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 1 Aug 2015 21:02:35 -0700 Subject: [PATCH 09/34] polishing runtests --- tools/run_tests/jobset.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/run_tests/jobset.py b/tools/run_tests/jobset.py index ec25b476102..e5e778a3f16 100755 --- a/tools/run_tests/jobset.py +++ b/tools/run_tests/jobset.py @@ -130,7 +130,8 @@ def which(filename): class JobSpec(object): """Specifies what to run for a job.""" - def __init__(self, cmdline, shortname=None, environ=None, hash_targets=None, cwd=None, shell=False): + def __init__(self, cmdline, shortname=None, environ=None, hash_targets=None, + cwd=None, shell=False, timeout_seconds=900): """ Arguments: cmdline: a list of arguments to pass as the command line @@ -148,6 +149,7 @@ class JobSpec(object): self.hash_targets = hash_targets or [] self.cwd = cwd self.shell = shell + self.timeout_seconds = timeout_seconds def identity(self): return '%r %r %r' % (self.cmdline, self.environ, self.hash_targets) @@ -206,7 +208,7 @@ class Job(object): do_newline=self._newline_on_success or self._travis) if self._bin_hash: update_cache.finished(self._spec.identity(), self._bin_hash) - elif self._state == _RUNNING and time.time() - self._start > 900: + elif self._state == _RUNNING and time.time() - self._start > self._spec.timeout_seconds: self._tempfile.seek(0) stdout = self._tempfile.read() filtered_stdout = filter(lambda x: x in string.printable, stdout.decode(errors='ignore')) From 02039a25c7a906cabbdca8b2cc04b5ace6039394 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Sun, 2 Aug 2015 16:26:59 -0700 Subject: [PATCH 10/34] Fail early and explicitly if protoc, pod, or xcodebuild are missing --- src/objective-c/tests/build_tests.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/objective-c/tests/build_tests.sh b/src/objective-c/tests/build_tests.sh index d98e0a769c6..a8b75030329 100755 --- a/src/objective-c/tests/build_tests.sh +++ b/src/objective-c/tests/build_tests.sh @@ -32,6 +32,10 @@ set -e cd $(dirname $0) +hash protoc 2>/dev/null || { echo >&2 "protoc needs to be installed."; exit 1; } +hash pod 2>/dev/null || { echo >&2 "Cocoapods needs to be installed."; exit 1; } +hash xcodebuild 2>/dev/null || { echo >&2 "XCode command-line tools need to be installed."; exit 1; } + # The local test server needs to be compiled before this because pod install of # gRPC renames some C gRPC files and not the server's code references to them. # From e95f241c96a5232d0da5004539f3d0e82e87816d Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Sun, 2 Aug 2015 16:27:53 -0700 Subject: [PATCH 11/34] Reactivate Cocoapods error output --- src/objective-c/tests/build_tests.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/objective-c/tests/build_tests.sh b/src/objective-c/tests/build_tests.sh index a8b75030329..3ac43fb5108 100755 --- a/src/objective-c/tests/build_tests.sh +++ b/src/objective-c/tests/build_tests.sh @@ -38,6 +38,4 @@ hash xcodebuild 2>/dev/null || { echo >&2 "XCode command-line tools need to be i # The local test server needs to be compiled before this because pod install of # gRPC renames some C gRPC files and not the server's code references to them. -# -# Suppress error output because Cocoapods issue #3823 causes a flooding warning. -pod install 2>/dev/null +pod install From c5ae3eb8d65287c1e4493523196e2abb5aa86d2e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 3 Aug 2015 10:42:22 -0700 Subject: [PATCH 12/34] Rename grpc_server_add_http2_port to grpc_server_add_insecure_http2_port --- include/grpc/grpc.h | 2 +- src/core/surface/server_chttp2.c | 2 +- src/cpp/server/insecure_server_credentials.cc | 2 +- src/csharp/ext/grpc_csharp_ext.c | 2 +- src/node/ext/server.cc | 4 ++-- src/php/ext/grpc/server.c | 2 +- src/python/grpcio/grpc/_adapter/_c/types/server.c | 2 +- src/ruby/ext/grpc/rb_server.c | 3 ++- test/core/end2end/dualstack_socket_test.c | 4 ++-- test/core/end2end/fixtures/chttp2_fullstack.c | 2 +- test/core/end2end/fixtures/chttp2_fullstack_compression.c | 2 +- test/core/end2end/fixtures/chttp2_fullstack_uds_posix.c | 2 +- .../end2end/fixtures/chttp2_fullstack_uds_posix_with_poll.c | 2 +- test/core/end2end/fixtures/chttp2_fullstack_with_poll.c | 2 +- test/core/end2end/multiple_server_queues_test.c | 2 +- test/core/fling/server.c | 2 +- 16 files changed, 19 insertions(+), 18 deletions(-) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 616aab7a81d..d9dd79ab658 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -562,7 +562,7 @@ void grpc_server_register_completion_queue(grpc_server *server, /** Add a HTTP2 over plaintext over tcp listener. Returns bound port number on success, 0 on failure. REQUIRES: server not started */ -int grpc_server_add_http2_port(grpc_server *server, const char *addr); +int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr); /** Start a server - tells all listeners to start listening */ void grpc_server_start(grpc_server *server); diff --git a/src/core/surface/server_chttp2.c b/src/core/surface/server_chttp2.c index 78c53466b38..4ab845bc008 100644 --- a/src/core/surface/server_chttp2.c +++ b/src/core/surface/server_chttp2.c @@ -80,7 +80,7 @@ static void destroy(grpc_server *server, void *tcpp) { grpc_tcp_server_destroy(tcp, grpc_server_listener_destroy_done, server); } -int grpc_server_add_http2_port(grpc_server *server, const char *addr) { +int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr) { grpc_resolved_addresses *resolved = NULL; grpc_tcp_server *tcp = NULL; size_t i; diff --git a/src/cpp/server/insecure_server_credentials.cc b/src/cpp/server/insecure_server_credentials.cc index aca3568e597..800cd36caaf 100644 --- a/src/cpp/server/insecure_server_credentials.cc +++ b/src/cpp/server/insecure_server_credentials.cc @@ -41,7 +41,7 @@ class InsecureServerCredentialsImpl GRPC_FINAL : public ServerCredentials { public: int AddPortToServer(const grpc::string& addr, grpc_server* server) GRPC_OVERRIDE { - return grpc_server_add_http2_port(server, addr.c_str()); + return grpc_server_add_insecure_http2_port(server, addr.c_str()); } }; } // namespace diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index 49a0471042c..fd6416a5d8c 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -715,7 +715,7 @@ grpcsharp_server_create(grpc_completion_queue *cq, GPR_EXPORT gpr_int32 GPR_CALLTYPE grpcsharp_server_add_insecure_http2_port(grpc_server *server, const char *addr) { - return grpc_server_add_http2_port(server, addr); + return grpc_server_add_insecure_http2_port(server, addr); } GPR_EXPORT void GPR_CALLTYPE grpcsharp_server_start(grpc_server *server) { diff --git a/src/node/ext/server.cc b/src/node/ext/server.cc index 04fabc871d2..1dc179db3d7 100644 --- a/src/node/ext/server.cc +++ b/src/node/ext/server.cc @@ -265,8 +265,8 @@ NAN_METHOD(Server::AddHttp2Port) { grpc_server_credentials *creds = creds_object->GetWrappedServerCredentials(); int port; if (creds == NULL) { - port = grpc_server_add_http2_port(server->wrapped_server, - *NanUtf8String(args[0])); + port = grpc_server_add_insecure_http2_port(server->wrapped_server, + *NanUtf8String(args[0])); } else { port = grpc_server_add_secure_http2_port(server->wrapped_server, *NanUtf8String(args[0]), diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index 8b8d5b2f476..d58aa884ca8 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -182,7 +182,7 @@ PHP_METHOD(Server, addHttp2Port) { "add_http2_port expects a string", 1 TSRMLS_CC); return; } - RETURN_LONG(grpc_server_add_http2_port(server->wrapped, addr)); + RETURN_LONG(grpc_server_add_insecure_http2_port(server->wrapped, addr)); } PHP_METHOD(Server, addSecureHttp2Port) { diff --git a/src/python/grpcio/grpc/_adapter/_c/types/server.c b/src/python/grpcio/grpc/_adapter/_c/types/server.c index 2a00f34039c..c2190ea672d 100644 --- a/src/python/grpcio/grpc/_adapter/_c/types/server.c +++ b/src/python/grpcio/grpc/_adapter/_c/types/server.c @@ -155,7 +155,7 @@ PyObject *pygrpc_Server_add_http2_port( port = grpc_server_add_secure_http2_port( self->c_serv, addr, creds->c_creds); } else { - port = grpc_server_add_http2_port(self->c_serv, addr); + port = grpc_server_add_insecure_http2_port(self->c_serv, addr); } return PyInt_FromLong(port); diff --git a/src/ruby/ext/grpc/rb_server.c b/src/ruby/ext/grpc/rb_server.c index 375a651d247..79a4ae8757b 100644 --- a/src/ruby/ext/grpc/rb_server.c +++ b/src/ruby/ext/grpc/rb_server.c @@ -357,7 +357,8 @@ static VALUE grpc_rb_server_add_http2_port(int argc, VALUE *argv, VALUE self) { rb_raise(rb_eRuntimeError, "destroyed!"); return Qnil; } else if (rb_creds == Qnil) { - recvd_port = grpc_server_add_http2_port(s->wrapped, StringValueCStr(port)); + recvd_port = + grpc_server_add_insecure_http2_port(s->wrapped, StringValueCStr(port)); if (recvd_port == 0) { rb_raise(rb_eRuntimeError, "could not add port %s to server, not sure why", diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c index 77bea2ababd..c98baeffdab 100644 --- a/test/core/end2end/dualstack_socket_test.c +++ b/test/core/end2end/dualstack_socket_test.c @@ -96,8 +96,8 @@ void test_connect(const char *server_host, const char *client_host, int port, cq = grpc_completion_queue_create(); server = grpc_server_create(NULL); grpc_server_register_completion_queue(server, cq); - GPR_ASSERT((got_port = grpc_server_add_http2_port(server, server_hostport)) > - 0); + GPR_ASSERT((got_port = grpc_server_add_insecure_http2_port( + server, server_hostport)) > 0); if (port == 0) { port = got_port; } else { diff --git a/test/core/end2end/fixtures/chttp2_fullstack.c b/test/core/end2end/fixtures/chttp2_fullstack.c index 6647b949ba2..53a6f0d7a57 100644 --- a/test/core/end2end/fixtures/chttp2_fullstack.c +++ b/test/core/end2end/fixtures/chttp2_fullstack.c @@ -84,7 +84,7 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, } f->server = grpc_server_create(server_args); grpc_server_register_completion_queue(f->server, f->cq); - GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr)); + GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } diff --git a/test/core/end2end/fixtures/chttp2_fullstack_compression.c b/test/core/end2end/fixtures/chttp2_fullstack_compression.c index f3d1fa22dce..0ee24c01b53 100644 --- a/test/core/end2end/fixtures/chttp2_fullstack_compression.c +++ b/test/core/end2end/fixtures/chttp2_fullstack_compression.c @@ -99,7 +99,7 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture *f, } f->server = grpc_server_create(ffd->server_args_compression); grpc_server_register_completion_queue(f->server, f->cq); - GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr)); + GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } diff --git a/test/core/end2end/fixtures/chttp2_fullstack_uds_posix.c b/test/core/end2end/fixtures/chttp2_fullstack_uds_posix.c index 89ad7b8c2d8..20afdb868e9 100644 --- a/test/core/end2end/fixtures/chttp2_fullstack_uds_posix.c +++ b/test/core/end2end/fixtures/chttp2_fullstack_uds_posix.c @@ -89,7 +89,7 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, } f->server = grpc_server_create(server_args); grpc_server_register_completion_queue(f->server, f->cq); - GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr)); + GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } diff --git a/test/core/end2end/fixtures/chttp2_fullstack_uds_posix_with_poll.c b/test/core/end2end/fixtures/chttp2_fullstack_uds_posix_with_poll.c index a2ab25d886f..8491ea6970d 100644 --- a/test/core/end2end/fixtures/chttp2_fullstack_uds_posix_with_poll.c +++ b/test/core/end2end/fixtures/chttp2_fullstack_uds_posix_with_poll.c @@ -89,7 +89,7 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, } f->server = grpc_server_create(server_args); grpc_server_register_completion_queue(f->server, f->cq); - GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr)); + GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } diff --git a/test/core/end2end/fixtures/chttp2_fullstack_with_poll.c b/test/core/end2end/fixtures/chttp2_fullstack_with_poll.c index 93786d0943a..2a4835add12 100644 --- a/test/core/end2end/fixtures/chttp2_fullstack_with_poll.c +++ b/test/core/end2end/fixtures/chttp2_fullstack_with_poll.c @@ -83,7 +83,7 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture *f, } f->server = grpc_server_create(server_args); grpc_server_register_completion_queue(f->server, f->cq); - GPR_ASSERT(grpc_server_add_http2_port(f->server, ffd->localaddr)); + GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr)); grpc_server_start(f->server); } diff --git a/test/core/end2end/multiple_server_queues_test.c b/test/core/end2end/multiple_server_queues_test.c index 208d42e6e74..7772d14ba5f 100644 --- a/test/core/end2end/multiple_server_queues_test.c +++ b/test/core/end2end/multiple_server_queues_test.c @@ -45,7 +45,7 @@ int main(int argc, char **argv) { cq2 = grpc_completion_queue_create(); server = grpc_server_create(NULL); grpc_server_register_completion_queue(server, cq1); - grpc_server_add_http2_port(server, "[::]:0"); + grpc_server_add_insecure_http2_port(server, "[::]:0"); grpc_server_register_completion_queue(server, cq2); grpc_server_start(server); grpc_server_shutdown_and_notify(server, cq2, NULL); diff --git a/test/core/fling/server.c b/test/core/fling/server.c index 8f349044d97..f445c681782 100644 --- a/test/core/fling/server.c +++ b/test/core/fling/server.c @@ -216,7 +216,7 @@ int main(int argc, char **argv) { grpc_server_credentials_release(ssl_creds); } else { server = grpc_server_create(NULL); - GPR_ASSERT(grpc_server_add_http2_port(server, addr)); + GPR_ASSERT(grpc_server_add_insecure_http2_port(server, addr)); } grpc_server_register_completion_queue(server, cq); grpc_server_start(server); From deab29e1821f1d7b5b074a42440ea9adcb51b15e Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 3 Aug 2015 12:32:44 -0700 Subject: [PATCH 13/34] Fix compilation under VS 2010 --- src/core/iomgr/tcp_windows.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/iomgr/tcp_windows.c b/src/core/iomgr/tcp_windows.c index 5e0457a37b1..89aa741470c 100644 --- a/src/core/iomgr/tcp_windows.c +++ b/src/core/iomgr/tcp_windows.c @@ -369,14 +369,16 @@ static grpc_endpoint_write_status win_write(grpc_endpoint *ep, } static void win_add_to_pollset(grpc_endpoint *ep, grpc_pollset *ps) { + grpc_tcp *tcp; (void) ps; - grpc_tcp *tcp = (grpc_tcp *) ep; + tcp = (grpc_tcp *) ep; grpc_iocp_add_socket(tcp->socket); } static void win_add_to_pollset_set(grpc_endpoint *ep, grpc_pollset_set *pss) { + grpc_tcp *tcp; (void) pss; - grpc_tcp *tcp = (grpc_tcp *) ep; + tcp = (grpc_tcp *) ep; grpc_iocp_add_socket(tcp->socket); } From 70787578f606de82f0e0800dcc5a14faaa9f089d Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Tue, 4 Aug 2015 00:24:19 +0200 Subject: [PATCH 14/34] Adding a sanity check that the cached makefile variables aren't committed. --- tools/run_tests/run_sanity.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/run_tests/run_sanity.sh b/tools/run_tests/run_sanity.sh index ebb09d94696..4df696706a0 100755 --- a/tools/run_tests/run_sanity.sh +++ b/tools/run_tests/run_sanity.sh @@ -48,3 +48,8 @@ diff -u $submodules - << EOF 3e2c8a5dd79481e1d36572cdf65be93514ba6581 third_party/protobuf (v3.0.0-alpha-1-1048-g3e2c8a5) 50893291621658f355bc5b4d450a8d06a563053d third_party/zlib (v1.2.8) EOF + +if [ -f cache.mk ] ; then + echo "Please don't commit cache.mk" + exit 1 +fi From 37a44d875f4f9520a58bf817315ef18f5da7c2a7 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Mon, 3 Aug 2015 15:40:54 -0700 Subject: [PATCH 15/34] =?UTF-8?q?Use=20the=20protoc=20made=20when=20one=20?= =?UTF-8?q?isn=E2=80=99t=20yet=20installed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RemoteTestClient/RemoteTest.podspec | 5 +++- .../RouteGuideClient/RouteGuide.podspec | 5 +++- src/objective-c/tests/build_tests.sh | 25 ++++++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec b/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec index 6b00efebb8b..8710753e596 100644 --- a/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec +++ b/src/objective-c/generated_libraries/RemoteTestClient/RemoteTest.podspec @@ -8,7 +8,10 @@ Pod::Spec.new do |s| # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients. s.prepare_command = <<-CMD - protoc --plugin=protoc-gen-grpc=../../../../bins/$CONFIG/grpc_objective_c_plugin --objc_out=. --grpc_out=. *.proto + BINDIR=../../../../bins/$CONFIG + PROTOC=$BINDIR/protobuf/protoc + PLUGIN=$BINDIR/grpc_objective_c_plugin + $PROTOC --plugin=protoc-gen-grpc=$PLUGIN --objc_out=. --grpc_out=. *.proto CMD s.subspec "Messages" do |ms| diff --git a/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec b/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec index 2c9cead7cf2..23ccffe69da 100644 --- a/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec +++ b/src/objective-c/generated_libraries/RouteGuideClient/RouteGuide.podspec @@ -8,7 +8,10 @@ Pod::Spec.new do |s| # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients. s.prepare_command = <<-CMD - protoc --plugin=protoc-gen-grpc=../../../../bins/$CONFIG/grpc_objective_c_plugin --objc_out=. --grpc_out=. *.proto + BINDIR=../../../../bins/$CONFIG + PROTOC=$BINDIR/protobuf/protoc + PLUGIN=$BINDIR/grpc_objective_c_plugin + $PROTOC --plugin=protoc-gen-grpc=$PLUGIN --objc_out=. --grpc_out=. *.proto CMD s.subspec "Messages" do |ms| diff --git a/src/objective-c/tests/build_tests.sh b/src/objective-c/tests/build_tests.sh index 3ac43fb5108..9a1bf7fd587 100755 --- a/src/objective-c/tests/build_tests.sh +++ b/src/objective-c/tests/build_tests.sh @@ -32,10 +32,29 @@ set -e cd $(dirname $0) -hash protoc 2>/dev/null || { echo >&2 "protoc needs to be installed."; exit 1; } hash pod 2>/dev/null || { echo >&2 "Cocoapods needs to be installed."; exit 1; } hash xcodebuild 2>/dev/null || { echo >&2 "XCode command-line tools need to be installed."; exit 1; } -# The local test server needs to be compiled before this because pod install of -# gRPC renames some C gRPC files and not the server's code references to them. +BINDIR=../../../bins/$CONFIG + +if [ ! -f $BINDIR/protobuf/protoc ]; then + hash protoc 2>/dev/null || { + echo >&2 "Can't find protoc. Make sure run_tests.py is making" \ + "grpc_objective_c_plugin before calling this script." + exit 1 + } + # When protoc is already installed, make doesn't compile one. Put a link + # there so the podspecs can do codegen using that path. + mkdir -p $BINDIR/protobuf + ln -s `which protoc` $BINDIR/protobuf/protoc +fi + +[ -f $BINDIR/interop_server ] || { + echo >&2 "Can't find the test server. Make sure run_tests.py is making" \ + "interop_server before calling this script. It needs to be done" \ + "before because pod install of gRPC renames some C gRPC files" \ + "and not the server's code references to them." + exit 1 +} + pod install From e8d953557dd9254b68f9b39e936585a7524b0388 Mon Sep 17 00:00:00 2001 From: Jorge Canizales Date: Mon, 3 Aug 2015 15:41:11 -0700 Subject: [PATCH 16/34] Formatting and documentation --- src/objective-c/tests/build_tests.sh | 8 +++++++- src/objective-c/tests/run_tests.sh | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/objective-c/tests/build_tests.sh b/src/objective-c/tests/build_tests.sh index 9a1bf7fd587..e7ad31e4031 100755 --- a/src/objective-c/tests/build_tests.sh +++ b/src/objective-c/tests/build_tests.sh @@ -28,12 +28,18 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# Don't run this script standalone. Instead, run from the repository root: +# ./tools/run_tests/run_tests.py -l objc + set -e cd $(dirname $0) hash pod 2>/dev/null || { echo >&2 "Cocoapods needs to be installed."; exit 1; } -hash xcodebuild 2>/dev/null || { echo >&2 "XCode command-line tools need to be installed."; exit 1; } +hash xcodebuild 2>/dev/null || { + echo >&2 "XCode command-line tools need to be installed." + exit 1 +} BINDIR=../../../bins/$CONFIG diff --git a/src/objective-c/tests/run_tests.sh b/src/objective-c/tests/run_tests.sh index 9afec687d68..b13c0f06334 100755 --- a/src/objective-c/tests/run_tests.sh +++ b/src/objective-c/tests/run_tests.sh @@ -28,6 +28,9 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# Don't run this script standalone. Instead, run from the repository root: +# ./tools/run_tests/run_tests.py -l objc + set -e cd $(dirname $0) From 2f25d98ba5788f0a6e487ecec7e358131180b56f Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 3 Aug 2015 18:01:26 -0700 Subject: [PATCH 17/34] properly decrement active_ports --- src/core/iomgr/tcp_server_windows.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/core/iomgr/tcp_server_windows.c b/src/core/iomgr/tcp_server_windows.c index bcd2aa8536f..260948c76f8 100644 --- a/src/core/iomgr/tcp_server_windows.c +++ b/src/core/iomgr/tcp_server_windows.c @@ -186,6 +186,17 @@ error: return -1; } +static void decrement_active_ports_and_notify(server_port *sp) { + sp->shutting_down = 0; + sp->socket->read_info.outstanding = 0; + gpr_mu_lock(&sp->server->mu); + GPR_ASSERT(sp->server->active_ports > 0); + if (0 == --sp->server->active_ports) { + gpr_cv_broadcast(&sp->server->cv); + } + gpr_mu_unlock(&sp->server->mu); +} + /* start_accept will reference that for the IOCP notification request. */ static void on_accept(void *arg, int from_iocp); @@ -234,6 +245,11 @@ static void start_accept(server_port *port) { return; failure: + if (port->shutting_down) { + /* We are abandoning the listener port, take that into account to prevent + occasional hangs on shutdown. */ + decrement_active_ports_and_notify(port); + } utf8_message = gpr_format_message(WSAGetLastError()); gpr_log(GPR_ERROR, message, utf8_message); gpr_free(utf8_message); @@ -277,14 +293,7 @@ static void on_accept(void *arg, int from_iocp) { if (sp->shutting_down) { /* During the shutdown case, we ARE expecting an error. So that's well, and we can wake up the shutdown thread. */ - sp->shutting_down = 0; - sp->socket->read_info.outstanding = 0; - gpr_mu_lock(&sp->server->mu); - GPR_ASSERT(sp->server->active_ports > 0); - if (0 == --sp->server->active_ports) { - gpr_cv_broadcast(&sp->server->cv); - } - gpr_mu_unlock(&sp->server->mu); + decrement_active_ports_and_notify(sp); return; } else { char *utf8_message = gpr_format_message(WSAGetLastError()); From e60c5e38106e85363ea0c6bba242e26f76681883 Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Tue, 4 Aug 2015 13:16:48 +0200 Subject: [PATCH 18/34] Use an unsigned pointer compare, as the highest bit may sometimes be set. This fixes intermittent connection issues on 32-bit Linux. Also related to issues #2557 and #2600. --- src/core/iomgr/fd_posix.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/iomgr/fd_posix.c b/src/core/iomgr/fd_posix.c index a2df838d4a0..91051a178ec 100644 --- a/src/core/iomgr/fd_posix.c +++ b/src/core/iomgr/fd_posix.c @@ -376,13 +376,15 @@ gpr_uint32 grpc_fd_begin_poll(grpc_fd *fd, grpc_pollset *pollset, return 0; } /* if there is nobody polling for read, but we need to, then start doing so */ - if (read_mask && !fd->read_watcher && gpr_atm_acq_load(&fd->readst) > READY) { + if (read_mask && !fd->read_watcher && + gpr_atm_acq_load((gpr_uintptr *)&fd->readst) > READY) { fd->read_watcher = watcher; mask |= read_mask; } /* if there is nobody polling for write, but we need to, then start doing so */ - if (write_mask && !fd->write_watcher && gpr_atm_acq_load(&fd->writest) > READY) { + if (write_mask && !fd->write_watcher && + gpr_atm_acq_load((gpr_uintptr *)&fd->writest) > READY) { fd->write_watcher = watcher; mask |= write_mask; } From abd60a39d5aa15dee027ab1757a79dd90db24df1 Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Tue, 4 Aug 2015 13:47:46 +0200 Subject: [PATCH 19/34] Change cast to avoid warning --- src/core/iomgr/fd_posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/iomgr/fd_posix.c b/src/core/iomgr/fd_posix.c index 91051a178ec..cbc141a2d00 100644 --- a/src/core/iomgr/fd_posix.c +++ b/src/core/iomgr/fd_posix.c @@ -377,14 +377,14 @@ gpr_uint32 grpc_fd_begin_poll(grpc_fd *fd, grpc_pollset *pollset, } /* if there is nobody polling for read, but we need to, then start doing so */ if (read_mask && !fd->read_watcher && - gpr_atm_acq_load((gpr_uintptr *)&fd->readst) > READY) { + (gpr_uintptr)gpr_atm_acq_load(&fd->readst) > READY) { fd->read_watcher = watcher; mask |= read_mask; } /* if there is nobody polling for write, but we need to, then start doing so */ if (write_mask && !fd->write_watcher && - gpr_atm_acq_load((gpr_uintptr *)&fd->writest) > READY) { + (gpr_uintptr)gpr_atm_acq_load(&fd->writest) > READY) { fd->write_watcher = watcher; mask |= write_mask; } From dd8a80fa9a11fc6f77db0b9c4bc2edf25b89f174 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 4 Aug 2015 11:05:56 -0700 Subject: [PATCH 20/34] clarified comment and silenced error log --- src/core/iomgr/tcp_server_windows.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/iomgr/tcp_server_windows.c b/src/core/iomgr/tcp_server_windows.c index 260948c76f8..0adbe9507c7 100644 --- a/src/core/iomgr/tcp_server_windows.c +++ b/src/core/iomgr/tcp_server_windows.c @@ -247,8 +247,12 @@ static void start_accept(server_port *port) { failure: if (port->shutting_down) { /* We are abandoning the listener port, take that into account to prevent - occasional hangs on shutdown. */ + occasional hangs on shutdown. The hang happens when sp->shutting_down + change is not seen by on_accept and we proceed to trying new accept, + but we fail there because the listening port has been closed in the + meantime. */ decrement_active_ports_and_notify(port); + return; } utf8_message = gpr_format_message(WSAGetLastError()); gpr_log(GPR_ERROR, message, utf8_message); From 0175e18133bf8cd74363ef08b8f3485038e3a36d Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 3 Aug 2015 18:10:19 -0700 Subject: [PATCH 21/34] tolerate occasional StatusCode.Internal on timeout --- src/csharp/Grpc.Core.Tests/TimeoutsTest.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs b/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs index 010ffd898a0..a09273b846f 100644 --- a/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs +++ b/src/csharp/Grpc.Core.Tests/TimeoutsTest.cs @@ -134,7 +134,8 @@ namespace Grpc.Core.Tests } catch (RpcException e) { - Assert.AreEqual(StatusCode.DeadlineExceeded, e.Status.StatusCode); + // We can't guarantee the status code always DeadlineExceeded. See issue #2685. + Assert.Contains(e.Status.StatusCode, new[] { StatusCode.DeadlineExceeded, StatusCode.Internal }); } } @@ -151,7 +152,8 @@ namespace Grpc.Core.Tests } catch (RpcException e) { - Assert.AreEqual(StatusCode.DeadlineExceeded, e.Status.StatusCode); + // We can't guarantee the status code always DeadlineExceeded. See issue #2685. + Assert.Contains(e.Status.StatusCode, new[] { StatusCode.DeadlineExceeded, StatusCode.Internal }); } } @@ -168,7 +170,8 @@ namespace Grpc.Core.Tests } catch (RpcException e) { - Assert.AreEqual(StatusCode.DeadlineExceeded, e.Status.StatusCode); + // We can't guarantee the status code is always DeadlineExceeded. See issue #2685. + Assert.Contains(e.Status.StatusCode, new[] { StatusCode.DeadlineExceeded, StatusCode.Internal }); } Assert.AreEqual("CANCELLED", stringFromServerHandlerTcs.Task.Result); } From d8bbdeae42ce6ae6077e4e5b4b4f4c673acecf57 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 22 Jul 2015 12:51:06 -0700 Subject: [PATCH 22/34] Added channel state API --- src/csharp/Grpc.Auth/OAuth2Interceptors.cs | 2 - src/csharp/Grpc.Core.Tests/ChannelTest.cs | 82 +++++++++++++++++++ .../Grpc.Core.Tests/ClientServerTest.cs | 24 ++++++ .../Grpc.Core.Tests/Grpc.Core.Tests.csproj | 1 + .../Grpc.Core.Tests/NUnitVersionTest.cs | 4 +- src/csharp/Grpc.Core/Channel.cs | 74 ++++++++++++++++- src/csharp/Grpc.Core/ChannelState.cs | 69 ++++++++++++++++ src/csharp/Grpc.Core/Grpc.Core.csproj | 1 + .../Grpc.Core/Internal/ChannelSafeHandle.cs | 20 +++++ src/csharp/ext/grpc_csharp_ext.c | 12 +++ 10 files changed, 280 insertions(+), 9 deletions(-) create mode 100644 src/csharp/Grpc.Core.Tests/ChannelTest.cs create mode 100644 src/csharp/Grpc.Core/ChannelState.cs diff --git a/src/csharp/Grpc.Auth/OAuth2Interceptors.cs b/src/csharp/Grpc.Auth/OAuth2Interceptors.cs index c785ca5a16b..cc9d2c175ff 100644 --- a/src/csharp/Grpc.Auth/OAuth2Interceptors.cs +++ b/src/csharp/Grpc.Auth/OAuth2Interceptors.cs @@ -119,7 +119,5 @@ namespace Grpc.Auth return new Metadata.Entry(AuthorizationHeader, Schema + " " + accessToken); } } - - } } diff --git a/src/csharp/Grpc.Core.Tests/ChannelTest.cs b/src/csharp/Grpc.Core.Tests/ChannelTest.cs new file mode 100644 index 00000000000..bfe001b2920 --- /dev/null +++ b/src/csharp/Grpc.Core.Tests/ChannelTest.cs @@ -0,0 +1,82 @@ +#region Copyright notice and license + +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +using System; +using Grpc.Core; +using Grpc.Core.Internal; +using Grpc.Core.Utils; +using NUnit.Framework; + +namespace Grpc.Core.Tests +{ + public class ChannelTest + { + [TestFixtureTearDown] + public void CleanupClass() + { + GrpcEnvironment.Shutdown(); + } + + [Test] + public void Constructor_RejectsInvalidParams() + { + Assert.Throws(typeof(NullReferenceException), () => new Channel(null, Credentials.Insecure)); + } + + [Test] + public void State_IdleAfterCreation() + { + using (var channel = new Channel("localhost", Credentials.Insecure)) + { + Assert.AreEqual(ChannelState.Idle, channel.State); + } + } + + [Test] + public void WaitForStateChangedAsync_InvalidArgument() + { + using (var channel = new Channel("localhost", Credentials.Insecure)) + { + Assert.Throws(typeof(ArgumentException), () => channel.WaitForStateChangedAsync(ChannelState.FatalFailure)); + } + } + + [Test] + public void Dispose_IsIdempotent() + { + var channel = new Channel("localhost", Credentials.Insecure); + channel.Dispose(); + channel.Dispose(); + } + } +} diff --git a/src/csharp/Grpc.Core.Tests/ClientServerTest.cs b/src/csharp/Grpc.Core.Tests/ClientServerTest.cs index 540fe756c07..35924868caa 100644 --- a/src/csharp/Grpc.Core.Tests/ClientServerTest.cs +++ b/src/csharp/Grpc.Core.Tests/ClientServerTest.cs @@ -276,6 +276,30 @@ namespace Grpc.Core.Tests Assert.IsTrue(peer.Contains(Host)); } + [Test] + public async Task Channel_WaitForStateChangedAsync() + { + Assert.Throws(typeof(TaskCanceledException), + async () => await channel.WaitForStateChangedAsync(channel.State, DateTime.UtcNow.AddMilliseconds(10))); + + var stateChangedTask = channel.WaitForStateChangedAsync(channel.State); + + var internalCall = new Call(ServiceName, EchoMethod, channel, Metadata.Empty); + await Calls.AsyncUnaryCall(internalCall, "abc", CancellationToken.None); + + await stateChangedTask; + Assert.AreEqual(ChannelState.Ready, channel.State); + } + + [Test] + public async Task Channel_ConnectAsync() + { + await channel.ConnectAsync(); + Assert.AreEqual(ChannelState.Ready, channel.State); + await channel.ConnectAsync(DateTime.UtcNow.AddMilliseconds(1000)); + Assert.AreEqual(ChannelState.Ready, channel.State); + } + private static async Task EchoHandler(string request, ServerCallContext context) { foreach (Metadata.Entry metadataEntry in context.RequestHeaders) diff --git a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj index 242a60d098d..f2bf459dc50 100644 --- a/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj +++ b/src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj @@ -76,6 +76,7 @@ + diff --git a/src/csharp/Grpc.Core.Tests/NUnitVersionTest.cs b/src/csharp/Grpc.Core.Tests/NUnitVersionTest.cs index 600df1a18dd..3fa6ad09c02 100644 --- a/src/csharp/Grpc.Core.Tests/NUnitVersionTest.cs +++ b/src/csharp/Grpc.Core.Tests/NUnitVersionTest.cs @@ -70,10 +70,8 @@ namespace Grpc.Core.Tests [Test] public async Task NUnitVersionTest2() { - testRunCount ++; + testRunCount++; await Task.Delay(10); } - - } } diff --git a/src/csharp/Grpc.Core/Channel.cs b/src/csharp/Grpc.Core/Channel.cs index 18e6f2fda57..8a71afa01a3 100644 --- a/src/csharp/Grpc.Core/Channel.cs +++ b/src/csharp/Grpc.Core/Channel.cs @@ -37,6 +37,8 @@ using System.Threading; using System.Threading.Tasks; using Grpc.Core.Internal; +using Grpc.Core.Logging; +using Grpc.Core.Utils; namespace Grpc.Core { @@ -45,6 +47,8 @@ namespace Grpc.Core /// public class Channel : IDisposable { + static readonly ILogger Logger = GrpcEnvironment.Logger.ForType(); + readonly GrpcEnvironment environment; readonly ChannelSafeHandle handle; readonly List options; @@ -53,13 +57,14 @@ namespace Grpc.Core /// /// Creates a channel that connects to a specific host. - /// Port will default to 80 for an unsecure channel and to 443 a secure channel. + /// Port will default to 80 for an unsecure channel and to 443 for a secure channel. /// - /// The DNS name of IP address of the host. + /// The name or IP address of the host. /// Credentials to secure the channel. /// Channel options. public Channel(string host, Credentials credentials, IEnumerable options = null) { + Preconditions.CheckNotNull(host); this.environment = GrpcEnvironment.GetInstance(); this.options = options != null ? new List(options) : new List(); @@ -82,8 +87,8 @@ namespace Grpc.Core /// /// Creates a channel that connects to a specific host and port. /// - /// DNS name or IP address - /// the port + /// The name or IP address of the host. + /// The port. /// Credentials to secure the channel. /// Channel options. public Channel(string host, int port, Credentials credentials, IEnumerable options = null) : @@ -91,6 +96,67 @@ namespace Grpc.Core { } + /// + /// Gets current connectivity state of this channel. + /// + public ChannelState State + { + get + { + return handle.CheckConnectivityState(false); + } + } + + /// + /// Returned tasks completes once channel state has become different from + /// given lastObservedState. + /// If deadline is reached or and error occurs, returned task is cancelled. + /// + public Task WaitForStateChangedAsync(ChannelState lastObservedState, DateTime? deadline = null) + { + Preconditions.CheckArgument(lastObservedState != ChannelState.FatalFailure, + "FatalFailure is a terminal state. No further state changes can occur."); + var tcs = new TaskCompletionSource(); + var deadlineTimespec = deadline.HasValue ? Timespec.FromDateTime(deadline.Value) : Timespec.InfFuture; + var handler = new BatchCompletionDelegate((success, ctx) => + { + if (success) + { + tcs.SetResult(null); + } + else + { + tcs.SetCanceled(); + } + }); + handle.WatchConnectivityState(lastObservedState, deadlineTimespec, environment.CompletionQueue, environment.CompletionRegistry, handler); + return tcs.Task; + } + + /// + /// Allows explicitly requesting channel to connect without starting an RPC. + /// Returned task completes once state Ready was seen. If the deadline is reached, + /// or channel enters the FatalFailure state, the task is cancelled. + /// There is no need to call this explicitly unless your use case requires that. + /// Starting an RPC on a new channel will request connection implicitly. + /// + public async Task ConnectAsync(DateTime? deadline = null) + { + var currentState = handle.CheckConnectivityState(true); + while (currentState != ChannelState.Ready) + { + if (currentState == ChannelState.FatalFailure) + { + throw new OperationCanceledException("Channel has reached FatalFailure state."); + } + await WaitForStateChangedAsync(currentState, deadline); + currentState = handle.CheckConnectivityState(false); + } + } + + /// + /// Destroys the underlying channel. + /// public void Dispose() { Dispose(true); diff --git a/src/csharp/Grpc.Core/ChannelState.cs b/src/csharp/Grpc.Core/ChannelState.cs new file mode 100644 index 00000000000..d293b98f753 --- /dev/null +++ b/src/csharp/Grpc.Core/ChannelState.cs @@ -0,0 +1,69 @@ +#region Copyright notice and license + +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#endregion + +using System; + +namespace Grpc.Core +{ + /// + /// Connectivity state of a channel. + /// Based on grpc_connectivity_state from grpc/grpc.h + /// + public enum ChannelState + { + /// + /// Channel is idle + /// + Idle, + + /// + /// Channel is connecting + /// + Connecting, + + /// + /// Channel is ready for work + /// + Ready, + + /// + /// Channel has seen a failure but expects to recover + /// + TransientFailure, + + /// + /// Channel has seen a failure that it cannot recover from + /// + FatalFailure + } +} diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj index 940a6b8ac09..641b54baba3 100644 --- a/src/csharp/Grpc.Core/Grpc.Core.csproj +++ b/src/csharp/Grpc.Core/Grpc.Core.csproj @@ -115,6 +115,7 @@ + diff --git a/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs index 20815efbd35..c017560b564 100644 --- a/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs @@ -49,6 +49,13 @@ namespace Grpc.Core.Internal [DllImport("grpc_csharp_ext.dll")] static extern CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline); + [DllImport("grpc_csharp_ext.dll")] + static extern ChannelState grpcsharp_channel_check_connectivity_state(ChannelSafeHandle channel, int tryToConnect); + + [DllImport("grpc_csharp_ext.dll")] + static extern void grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel, ChannelState lastObservedState, + Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx); + [DllImport("grpc_csharp_ext.dll")] static extern void grpcsharp_channel_destroy(IntPtr channel); @@ -73,6 +80,19 @@ namespace Grpc.Core.Internal return result; } + public ChannelState CheckConnectivityState(bool tryToConnect) + { + return grpcsharp_channel_check_connectivity_state(this, tryToConnect ? 1 : 0); + } + + public void WatchConnectivityState(ChannelState lastObservedState, Timespec deadline, CompletionQueueSafeHandle cq, + CompletionRegistry completionRegistry, BatchCompletionDelegate callback) + { + var ctx = BatchContextSafeHandle.Create(); + completionRegistry.RegisterBatchCompletion(ctx, callback); + grpcsharp_channel_watch_connectivity_state(this, lastObservedState, deadline, cq, ctx); + } + protected override bool ReleaseHandle() { grpcsharp_channel_destroy(handle); diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index 49a0471042c..0e3a83d244b 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -382,6 +382,18 @@ grpcsharp_channel_create_call(grpc_channel *channel, grpc_completion_queue *cq, return grpc_channel_create_call(channel, cq, method, host, deadline); } +GPR_EXPORT grpc_connectivity_state GPR_CALLTYPE +grpcsharp_channel_check_connectivity_state(grpc_channel *channel, gpr_int32 try_to_connect) { + return grpc_channel_check_connectivity_state(channel, try_to_connect); +} + +GPR_EXPORT void GPR_CALLTYPE grpcsharp_channel_watch_connectivity_state( + grpc_channel *channel, grpc_connectivity_state last_observed_state, + gpr_timespec deadline, grpc_completion_queue *cq, grpcsharp_batch_context *ctx) { + grpc_channel_watch_connectivity_state(channel, last_observed_state, NULL, + deadline, cq, ctx); +} + /* Channel args */ GPR_EXPORT grpc_channel_args *GPR_CALLTYPE From 9d67d8deafe8cf170f9cf9498513bc22a17fc4c7 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 1 Aug 2015 20:39:16 -0700 Subject: [PATCH 23/34] add HealthCheck tests to run_tests.py --- tools/run_tests/run_tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index fa749498d2f..b93f5840953 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -254,6 +254,7 @@ class CSharpLanguage(object): def test_specs(self, config, travis): assemblies = ['Grpc.Core.Tests', 'Grpc.Examples.Tests', + 'Grpc.HealthCheck.Tests', 'Grpc.IntegrationTesting'] if self.platform == 'windows': cmd = 'tools\\run_tests\\run_csharp.bat' From 9c7e46f55c71bb8bd99e07ebebc924a195fc5957 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 1 Aug 2015 21:20:28 -0700 Subject: [PATCH 24/34] use NULL for default host in grpc_channel_call_create --- src/csharp/Grpc.Core/Channel.cs | 31 ---------------------- src/csharp/Grpc.Core/Internal/AsyncCall.cs | 2 +- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/src/csharp/Grpc.Core/Channel.cs b/src/csharp/Grpc.Core/Channel.cs index 8a71afa01a3..04fea8c9248 100644 --- a/src/csharp/Grpc.Core/Channel.cs +++ b/src/csharp/Grpc.Core/Channel.cs @@ -52,7 +52,6 @@ namespace Grpc.Core readonly GrpcEnvironment environment; readonly ChannelSafeHandle handle; readonly List options; - readonly string target; bool disposed; /// @@ -81,7 +80,6 @@ namespace Grpc.Core this.handle = ChannelSafeHandle.CreateInsecure(host, nativeChannelArgs); } } - this.target = GetOverridenTarget(host, this.options); } /// @@ -163,14 +161,6 @@ namespace Grpc.Core GC.SuppressFinalize(this); } - internal string Target - { - get - { - return target; - } - } - internal ChannelSafeHandle Handle { get @@ -225,26 +215,5 @@ namespace Grpc.Core // TODO(jtattermusch): it would be useful to also provide .NET/mono version. return string.Format("grpc-csharp/{0}", VersionInfo.CurrentVersion); } - - /// - /// Look for SslTargetNameOverride option and return its value instead of originalTarget - /// if found. - /// - private static string GetOverridenTarget(string originalTarget, IEnumerable options) - { - if (options == null) - { - return originalTarget; - } - foreach (var option in options) - { - if (option.Type == ChannelOption.OptionType.String - && option.Name == ChannelOptions.SslTargetNameOverride) - { - return option.StringValue; - } - } - return originalTarget; - } } } diff --git a/src/csharp/Grpc.Core/Internal/AsyncCall.cs b/src/csharp/Grpc.Core/Internal/AsyncCall.cs index bfcb9366a12..48f466460f5 100644 --- a/src/csharp/Grpc.Core/Internal/AsyncCall.cs +++ b/src/csharp/Grpc.Core/Internal/AsyncCall.cs @@ -67,7 +67,7 @@ namespace Grpc.Core.Internal public void Initialize(Channel channel, CompletionQueueSafeHandle cq, string methodName, Timespec deadline) { this.channel = channel; - var call = channel.Handle.CreateCall(channel.CompletionRegistry, cq, methodName, channel.Target, deadline); + var call = channel.Handle.CreateCall(channel.CompletionRegistry, cq, methodName, null, deadline); channel.Environment.DebugStats.ActiveClientCalls.Increment(); InitializeInternal(call); } From dead905b87c159ce8af7252c17f05cb3e40e7826 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Sat, 1 Aug 2015 21:34:31 -0700 Subject: [PATCH 25/34] expose Channel.Target property --- src/csharp/Grpc.Core.Tests/ChannelTest.cs | 9 +++++++++ src/csharp/Grpc.Core/Channel.cs | 9 +++++++++ src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs | 11 +++++++++++ src/csharp/ext/grpc_csharp_ext.c | 4 ++++ 4 files changed, 33 insertions(+) diff --git a/src/csharp/Grpc.Core.Tests/ChannelTest.cs b/src/csharp/Grpc.Core.Tests/ChannelTest.cs index bfe001b2920..60b45176e56 100644 --- a/src/csharp/Grpc.Core.Tests/ChannelTest.cs +++ b/src/csharp/Grpc.Core.Tests/ChannelTest.cs @@ -71,6 +71,15 @@ namespace Grpc.Core.Tests } } + [Test] + public void Target() + { + using (var channel = new Channel("127.0.0.1", Credentials.Insecure)) + { + Assert.IsTrue(channel.Target.Contains("127.0.0.1")); + } + } + [Test] public void Dispose_IsIdempotent() { diff --git a/src/csharp/Grpc.Core/Channel.cs b/src/csharp/Grpc.Core/Channel.cs index 04fea8c9248..0b696104438 100644 --- a/src/csharp/Grpc.Core/Channel.cs +++ b/src/csharp/Grpc.Core/Channel.cs @@ -131,6 +131,15 @@ namespace Grpc.Core return tcs.Task; } + /// Address of the remote endpoint in URI format. + public string Target + { + get + { + return handle.GetTarget(); + } + } + /// /// Allows explicitly requesting channel to connect without starting an RPC. /// Returned task completes once state Ready was seen. If the deadline is reached, diff --git a/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs b/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs index c017560b564..7324ebdf573 100644 --- a/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/ChannelSafeHandle.cs @@ -56,6 +56,9 @@ namespace Grpc.Core.Internal static extern void grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel, ChannelState lastObservedState, Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx); + [DllImport("grpc_csharp_ext.dll")] + static extern CStringSafeHandle grpcsharp_channel_get_target(ChannelSafeHandle call); + [DllImport("grpc_csharp_ext.dll")] static extern void grpcsharp_channel_destroy(IntPtr channel); @@ -93,6 +96,14 @@ namespace Grpc.Core.Internal grpcsharp_channel_watch_connectivity_state(this, lastObservedState, deadline, cq, ctx); } + public string GetTarget() + { + using (var cstring = grpcsharp_channel_get_target(this)) + { + return cstring.GetValue(); + } + } + protected override bool ReleaseHandle() { grpcsharp_channel_destroy(handle); diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index 0e3a83d244b..8e2a5f0269a 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -394,6 +394,10 @@ GPR_EXPORT void GPR_CALLTYPE grpcsharp_channel_watch_connectivity_state( deadline, cq, ctx); } +GPR_EXPORT char *GPR_CALLTYPE grpcsharp_channel_get_target(grpc_channel *channel) { + return grpc_channel_get_target(channel); +} + /* Channel args */ GPR_EXPORT grpc_channel_args *GPR_CALLTYPE From 07ea52c29c1274a7d40c5c505c1ef1b55701578f Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 3 Aug 2015 18:34:31 -0700 Subject: [PATCH 26/34] add DefaultAuthority constant to channel options --- src/csharp/Grpc.Core/ChannelOptions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/csharp/Grpc.Core/ChannelOptions.cs b/src/csharp/Grpc.Core/ChannelOptions.cs index 9fe03d2805d..f70408dae7f 100644 --- a/src/csharp/Grpc.Core/ChannelOptions.cs +++ b/src/csharp/Grpc.Core/ChannelOptions.cs @@ -135,6 +135,9 @@ namespace Grpc.Core /// Initial sequence number for http2 transports public const string Http2InitialSequenceNumber = "grpc.http2.initial_sequence_number"; + /// Default authority for calls. + public const string DefaultAuthority = "grpc.default_authority"; + /// Primary user agent: goes at the start of the user-agent metadata public const string PrimaryUserAgentString = "grpc.primary_user_agent"; From 9fb1d200f1fafc186cf40f2ae2863058da2d3b7e Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 4 Aug 2015 11:32:46 -0700 Subject: [PATCH 27/34] watch connectivity state API has changed in the meantime --- src/csharp/ext/grpc_csharp_ext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index 8e2a5f0269a..28c2791cac0 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -390,7 +390,7 @@ grpcsharp_channel_check_connectivity_state(grpc_channel *channel, gpr_int32 try_ GPR_EXPORT void GPR_CALLTYPE grpcsharp_channel_watch_connectivity_state( grpc_channel *channel, grpc_connectivity_state last_observed_state, gpr_timespec deadline, grpc_completion_queue *cq, grpcsharp_batch_context *ctx) { - grpc_channel_watch_connectivity_state(channel, last_observed_state, NULL, + grpc_channel_watch_connectivity_state(channel, last_observed_state, deadline, cq, ctx); } From 2ed6878412d54ad1a6509de45d6351a3f697bb48 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Tue, 4 Aug 2015 23:13:43 +0200 Subject: [PATCH 28/34] Fixing environments where pkg-config isn't installed. Depending on the presence of pkg-config, we're not necessarily doing the right thing in the Makefile. Zlib is a pkg-config dependency, but libm, libpthread, librt aren't. --- Makefile | 62 ++++++++++++++++++++++++------------- templates/Makefile.template | 62 ++++++++++++++++++++++++------------- 2 files changed, 82 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 8a38a689f99..4ad466dae85 100644 --- a/Makefile +++ b/Makefile @@ -268,34 +268,21 @@ INCLUDES = . include $(GENDIR) LDFLAGS += -Llibs/$(CONFIG) ifeq ($(SYSTEM),Darwin) -ifneq ($(wildcard /usr/local/ssl/include),) -INCLUDES += /usr/local/ssl/include -endif -ifneq ($(wildcard /opt/local/include),) -INCLUDES += /opt/local/include -endif -ifneq ($(wildcard /usr/local/include),) -INCLUDES += /usr/local/include -endif -LIBS = m z -ifneq ($(wildcard /usr/local/ssl/lib),) -LDFLAGS += -L/usr/local/ssl/lib -endif -ifneq ($(wildcard /opt/local/lib),) -LDFLAGS += -L/opt/local/lib -endif -ifneq ($(wildcard /usr/local/lib),) -LDFLAGS += -L/usr/local/lib -endif +LIBS += m endif ifeq ($(SYSTEM),Linux) -LIBS = rt m z pthread +LIBS += rt m pthread LDFLAGS += -pthread endif ifeq ($(SYSTEM),MINGW32) -LIBS = m z pthread +LIBS += m pthread +LDFLAGS += -pthread +endif + +ifeq ($(SYSTEM),FreeBSD) +LIBS += pthread LDFLAGS += -pthread endif @@ -387,6 +374,39 @@ ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0-alpha-3 protobuf else # HAS_PKG_CONFIG +ifeq ($(SYSTEM),Darwin) +ifneq ($(wildcard /usr/local/ssl/include),) +INCLUDES += /usr/local/ssl/include +endif +ifneq ($(wildcard /opt/local/include),) +INCLUDES += /opt/local/include +endif +ifneq ($(wildcard /usr/local/include),) +INCLUDES += /usr/local/include +endif +ifneq ($(wildcard /usr/local/ssl/lib),) +LDFLAGS += -L/usr/local/ssl/lib +endif +ifneq ($(wildcard /opt/local/lib),) +LDFLAGS += -L/opt/local/lib +endif +ifneq ($(wildcard /usr/local/lib),) +LDFLAGS += -L/usr/local/lib +endif +endif + +ifeq ($(SYSTEM),Linux) +LIBS += z +endif + +ifeq ($(SYSTEM),MINGW32) +LIBS += z +endif + +ifeq ($(SYSTEM),FreeBSD) +LIBS += z +endif + ifeq ($(SYSTEM),MINGW32) OPENSSL_LIBS = ssl32 eay32 else diff --git a/templates/Makefile.template b/templates/Makefile.template index 1e46db11dce..1883bd6c2f8 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -282,34 +282,21 @@ INCLUDES = . include $(GENDIR) LDFLAGS += -Llibs/$(CONFIG) ifeq ($(SYSTEM),Darwin) -ifneq ($(wildcard /usr/local/ssl/include),) -INCLUDES += /usr/local/ssl/include -endif -ifneq ($(wildcard /opt/local/include),) -INCLUDES += /opt/local/include -endif -ifneq ($(wildcard /usr/local/include),) -INCLUDES += /usr/local/include -endif -LIBS = m z -ifneq ($(wildcard /usr/local/ssl/lib),) -LDFLAGS += -L/usr/local/ssl/lib -endif -ifneq ($(wildcard /opt/local/lib),) -LDFLAGS += -L/opt/local/lib -endif -ifneq ($(wildcard /usr/local/lib),) -LDFLAGS += -L/usr/local/lib -endif +LIBS += m endif ifeq ($(SYSTEM),Linux) -LIBS = rt m z pthread +LIBS += rt m pthread LDFLAGS += -pthread endif ifeq ($(SYSTEM),MINGW32) -LIBS = m z pthread +LIBS += m pthread +LDFLAGS += -pthread +endif + +ifeq ($(SYSTEM),FreeBSD) +LIBS += pthread LDFLAGS += -pthread endif @@ -412,6 +399,39 @@ ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0-alpha-3 protobuf else # HAS_PKG_CONFIG +ifeq ($(SYSTEM),Darwin) +ifneq ($(wildcard /usr/local/ssl/include),) +INCLUDES += /usr/local/ssl/include +endif +ifneq ($(wildcard /opt/local/include),) +INCLUDES += /opt/local/include +endif +ifneq ($(wildcard /usr/local/include),) +INCLUDES += /usr/local/include +endif +ifneq ($(wildcard /usr/local/ssl/lib),) +LDFLAGS += -L/usr/local/ssl/lib +endif +ifneq ($(wildcard /opt/local/lib),) +LDFLAGS += -L/opt/local/lib +endif +ifneq ($(wildcard /usr/local/lib),) +LDFLAGS += -L/usr/local/lib +endif +endif + +ifeq ($(SYSTEM),Linux) +LIBS += z +endif + +ifeq ($(SYSTEM),MINGW32) +LIBS += z +endif + +ifeq ($(SYSTEM),FreeBSD) +LIBS += z +endif + ifeq ($(SYSTEM),MINGW32) OPENSSL_LIBS = ssl32 eay32 else From b335256444349361cf406b14bc846611b7249056 Mon Sep 17 00:00:00 2001 From: yang-g Date: Tue, 4 Aug 2015 14:42:06 -0700 Subject: [PATCH 29/34] Add AsyncNotifyWhenDone --- include/grpc++/server_context.h | 6 +++ src/cpp/server/server_context.cc | 13 ++++- test/cpp/end2end/async_end2end_test.cc | 74 ++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index cf2732b33d2..03d2f0d128d 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -125,6 +125,11 @@ class ServerContext { const struct census_context* census_context() const; + // Async only. Has to be called before the rpc starts. + // Returns the tag in completion queue when the rpc finishes. + // IsCancelled() can then be called to check whether the rpc was cancelled. + void AsyncNotifyWhenDone(void* tag) { async_notify_when_done_tag_ = tag; } + private: friend class ::grpc::testing::InteropContextInspector; friend class ::grpc::Server; @@ -165,6 +170,7 @@ class ServerContext { void set_call(grpc_call* call); CompletionOp* completion_op_; + void* async_notify_when_done_tag_; gpr_timespec deadline_; grpc_call* call_; diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index cf19556e7a0..0d09519b28d 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -57,9 +57,12 @@ class ServerContext::CompletionOp GRPC_FINAL : public CallOpSetInterface { bool CheckCancelled(CompletionQueue* cq); + void set_tag(void* tag) { tag_ = tag; } + void Unref(); private: + void* tag_; grpc::mutex mu_; int refs_; bool finalized_; @@ -90,18 +93,24 @@ void ServerContext::CompletionOp::FillOps(grpc_op* ops, size_t* nops) { bool ServerContext::CompletionOp::FinalizeResult(void** tag, bool* status) { grpc::unique_lock lock(mu_); finalized_ = true; + bool ret = false; + if (tag_) { + *tag = tag_; + ret = true; + } if (!*status) cancelled_ = 1; if (--refs_ == 0) { lock.unlock(); delete this; } - return false; + return ret; } // ServerContext body ServerContext::ServerContext() : completion_op_(nullptr), + async_notify_when_done_tag_(nullptr), call_(nullptr), cq_(nullptr), sent_initial_metadata_(false) {} @@ -109,6 +118,7 @@ ServerContext::ServerContext() ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, size_t metadata_count) : completion_op_(nullptr), + async_notify_when_done_tag_(nullptr), deadline_(deadline), call_(nullptr), cq_(nullptr), @@ -133,6 +143,7 @@ ServerContext::~ServerContext() { void ServerContext::BeginCompletionOp(Call* call) { GPR_ASSERT(!completion_op_); completion_op_ = new CompletionOp(); + completion_op_->set_tag(async_notify_when_done_tag_); call->PerformOps(completion_op_); } diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index b95bdf6b9b4..9b53bdc9990 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -592,6 +592,80 @@ TEST_F(AsyncEnd2endTest, MetadataRpc) { EXPECT_EQ(meta6.second, server_trailing_metadata.find(meta6.first)->second); EXPECT_GE(server_trailing_metadata.size(), static_cast(2)); } + +// Server uses AsyncNotifyWhenDone API to check for cancellation +TEST_F(AsyncEnd2endTest, ServerCheckCancellation) { + ResetStub(); + + EchoRequest send_request; + EchoRequest recv_request; + EchoResponse send_response; + EchoResponse recv_response; + Status recv_status; + + ClientContext cli_ctx; + ServerContext srv_ctx; + grpc::ServerAsyncResponseWriter response_writer(&srv_ctx); + + send_request.set_message("Hello"); + std::unique_ptr > response_reader( + stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); + + srv_ctx.AsyncNotifyWhenDone(tag(5)); + service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), + cq_.get(), tag(2)); + + Verifier().Expect(2, true).Verify(cq_.get()); + EXPECT_EQ(send_request.message(), recv_request.message()); + + cli_ctx.TryCancel(); + Verifier().Expect(5, true).Verify(cq_.get()); + EXPECT_TRUE(srv_ctx.IsCancelled()); + + response_reader->Finish(&recv_response, &recv_status, tag(4)); + Verifier().Expect(4, false).Verify(cq_.get()); + + EXPECT_EQ(StatusCode::CANCELLED, recv_status.error_code()); +} + +// Server uses AsyncNotifyWhenDone API to check for normal finish +TEST_F(AsyncEnd2endTest, ServerCheckDone) { + ResetStub(); + + EchoRequest send_request; + EchoRequest recv_request; + EchoResponse send_response; + EchoResponse recv_response; + Status recv_status; + + ClientContext cli_ctx; + ServerContext srv_ctx; + grpc::ServerAsyncResponseWriter response_writer(&srv_ctx); + + send_request.set_message("Hello"); + std::unique_ptr > response_reader( + stub_->AsyncEcho(&cli_ctx, send_request, cq_.get())); + + srv_ctx.AsyncNotifyWhenDone(tag(5)); + service_.RequestEcho(&srv_ctx, &recv_request, &response_writer, cq_.get(), + cq_.get(), tag(2)); + + Verifier().Expect(2, true).Verify(cq_.get()); + EXPECT_EQ(send_request.message(), recv_request.message()); + + send_response.set_message(recv_request.message()); + response_writer.Finish(send_response, Status::OK, tag(3)); + Verifier().Expect(3, true).Verify(cq_.get()); + Verifier().Expect(5, true).Verify(cq_.get()); + EXPECT_FALSE(srv_ctx.IsCancelled()); + + response_reader->Finish(&recv_response, &recv_status, tag(4)); + Verifier().Expect(4, true).Verify(cq_.get()); + + EXPECT_EQ(send_response.message(), recv_response.message()); + EXPECT_TRUE(recv_status.ok()); +} + } // namespace } // namespace testing } // namespace grpc From 517662cbf0e1a7f39c47fbb69ae45d9f01f7b0f6 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Wed, 5 Aug 2015 00:03:39 +0200 Subject: [PATCH 30/34] Moving our build status badge from Travis to Jenkins. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 36d9fa07caf..f8306298162 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Build Status](https://travis-ci.org/grpc/grpc.svg?branch=master)](https://travis-ci.org/grpc/grpc) +[![Build Status](https://grpc-testing.appspot.com/job/gRPC_master/badge/icon)](https://grpc-testing.appspot.com/job/gRPC_master) [![Coverage Status](https://img.shields.io/coveralls/grpc/grpc.svg)](https://coveralls.io/r/grpc/grpc?branch=master) [gRPC - An RPC library and framework](http://github.com/grpc/grpc) From 63541a1de15736df2a0e428f5c427581296f9773 Mon Sep 17 00:00:00 2001 From: Paul Marks Date: Tue, 4 Aug 2015 15:05:00 -0700 Subject: [PATCH 31/34] Return normalized IPv4 addresses from grpc_sockaddr_to_uri(). Users of the high-level API should not care whether we're using AF_INET or AF_INET6 sockets internally. --- src/core/iomgr/sockaddr_utils.c | 5 +++++ test/core/iomgr/sockaddr_utils_test.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/core/iomgr/sockaddr_utils.c b/src/core/iomgr/sockaddr_utils.c index 71ac12e87b9..65ec1f94ac8 100644 --- a/src/core/iomgr/sockaddr_utils.c +++ b/src/core/iomgr/sockaddr_utils.c @@ -170,6 +170,11 @@ int grpc_sockaddr_to_string(char **out, const struct sockaddr *addr, char *grpc_sockaddr_to_uri(const struct sockaddr *addr) { char *temp; char *result; + struct sockaddr_in addr_normalized; + + if (grpc_sockaddr_is_v4mapped(addr, &addr_normalized)) { + addr = (const struct sockaddr *)&addr_normalized; + } switch (addr->sa_family) { case AF_INET: diff --git a/test/core/iomgr/sockaddr_utils_test.c b/test/core/iomgr/sockaddr_utils_test.c index dfab3409597..72a0f718358 100644 --- a/test/core/iomgr/sockaddr_utils_test.c +++ b/test/core/iomgr/sockaddr_utils_test.c @@ -187,6 +187,15 @@ static void expect_sockaddr_str(const char *expected, void *addr, gpr_free(str); } +static void expect_sockaddr_uri(const char *expected, void *addr) { + char *str; + gpr_log(GPR_INFO, " expect_sockaddr_uri(%s)", expected); + str = grpc_sockaddr_to_uri((struct sockaddr *)addr); + GPR_ASSERT(str != NULL); + GPR_ASSERT(strcmp(expected, str) == 0); + gpr_free(str); +} + static void test_sockaddr_to_string(void) { struct sockaddr_in input4; struct sockaddr_in6 input6; @@ -199,23 +208,28 @@ static void test_sockaddr_to_string(void) { input4 = make_addr4(kIPv4, sizeof(kIPv4)); expect_sockaddr_str("192.0.2.1:12345", &input4, 0); expect_sockaddr_str("192.0.2.1:12345", &input4, 1); + expect_sockaddr_uri("ipv4:192.0.2.1:12345", &input4); input6 = make_addr6(kIPv6, sizeof(kIPv6)); expect_sockaddr_str("[2001:db8::1]:12345", &input6, 0); expect_sockaddr_str("[2001:db8::1]:12345", &input6, 1); + expect_sockaddr_uri("ipv6:[2001:db8::1]:12345", &input6); input6 = make_addr6(kMapped, sizeof(kMapped)); expect_sockaddr_str("[::ffff:192.0.2.1]:12345", &input6, 0); expect_sockaddr_str("192.0.2.1:12345", &input6, 1); + expect_sockaddr_uri("ipv4:192.0.2.1:12345", &input6); input6 = make_addr6(kNotQuiteMapped, sizeof(kNotQuiteMapped)); expect_sockaddr_str("[::fffe:c000:263]:12345", &input6, 0); expect_sockaddr_str("[::fffe:c000:263]:12345", &input6, 1); + expect_sockaddr_uri("ipv6:[::fffe:c000:263]:12345", &input6); memset(&dummy, 0, sizeof(dummy)); dummy.sa_family = 123; expect_sockaddr_str("(sockaddr family=123)", &dummy, 0); expect_sockaddr_str("(sockaddr family=123)", &dummy, 1); + GPR_ASSERT(grpc_sockaddr_to_uri(&dummy) == NULL); GPR_ASSERT(errno == 0x7EADBEEF); } From d45a26ed06dfeafa41f49d17fe42a2f637ad6742 Mon Sep 17 00:00:00 2001 From: yang-g Date: Tue, 4 Aug 2015 16:36:22 -0700 Subject: [PATCH 32/34] allow null tag --- include/grpc++/server_context.h | 6 +++++- src/cpp/server/server_context.cc | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/grpc++/server_context.h b/include/grpc++/server_context.h index 03d2f0d128d..23273f43e67 100644 --- a/include/grpc++/server_context.h +++ b/include/grpc++/server_context.h @@ -128,7 +128,10 @@ class ServerContext { // Async only. Has to be called before the rpc starts. // Returns the tag in completion queue when the rpc finishes. // IsCancelled() can then be called to check whether the rpc was cancelled. - void AsyncNotifyWhenDone(void* tag) { async_notify_when_done_tag_ = tag; } + void AsyncNotifyWhenDone(void* tag) { + has_notify_when_done_tag_ = true; + async_notify_when_done_tag_ = tag; + } private: friend class ::grpc::testing::InteropContextInspector; @@ -170,6 +173,7 @@ class ServerContext { void set_call(grpc_call* call); CompletionOp* completion_op_; + bool has_notify_when_done_tag_; void* async_notify_when_done_tag_; gpr_timespec deadline_; diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index 0d09519b28d..04373397f92 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -50,18 +50,22 @@ namespace grpc { class ServerContext::CompletionOp GRPC_FINAL : public CallOpSetInterface { public: // initial refs: one in the server context, one in the cq - CompletionOp() : refs_(2), finalized_(false), cancelled_(0) {} + CompletionOp() : has_tag_(false), tag_(nullptr), refs_(2), finalized_(false), cancelled_(0) {} void FillOps(grpc_op* ops, size_t* nops) GRPC_OVERRIDE; bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE; bool CheckCancelled(CompletionQueue* cq); - void set_tag(void* tag) { tag_ = tag; } + void set_tag(void* tag) { + has_tag_ = true; + tag_ = tag; + } void Unref(); private: + bool has_tag_; void* tag_; grpc::mutex mu_; int refs_; @@ -94,7 +98,7 @@ bool ServerContext::CompletionOp::FinalizeResult(void** tag, bool* status) { grpc::unique_lock lock(mu_); finalized_ = true; bool ret = false; - if (tag_) { + if (has_tag_) { *tag = tag_; ret = true; } @@ -110,6 +114,7 @@ bool ServerContext::CompletionOp::FinalizeResult(void** tag, bool* status) { ServerContext::ServerContext() : completion_op_(nullptr), + has_notify_when_done_tag_(false), async_notify_when_done_tag_(nullptr), call_(nullptr), cq_(nullptr), @@ -118,6 +123,7 @@ ServerContext::ServerContext() ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, size_t metadata_count) : completion_op_(nullptr), + has_notify_when_done_tag_(false), async_notify_when_done_tag_(nullptr), deadline_(deadline), call_(nullptr), @@ -143,7 +149,9 @@ ServerContext::~ServerContext() { void ServerContext::BeginCompletionOp(Call* call) { GPR_ASSERT(!completion_op_); completion_op_ = new CompletionOp(); - completion_op_->set_tag(async_notify_when_done_tag_); + if (has_notify_when_done_tag_) { + completion_op_->set_tag(async_notify_when_done_tag_); + } call->PerformOps(completion_op_); } From 60287b636375cf7ff6ff896b24deaa9c39884e53 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 5 Aug 2015 07:23:48 -0700 Subject: [PATCH 33/34] Revert "Fixing environments where pkg-config isn't installed." This reverts commit 2ed6878412d54ad1a6509de45d6351a3f697bb48. --- Makefile | 62 +++++++++++++------------------------ templates/Makefile.template | 62 +++++++++++++------------------------ 2 files changed, 42 insertions(+), 82 deletions(-) diff --git a/Makefile b/Makefile index 4ba0c0ffcf1..d9ede7a6e65 100644 --- a/Makefile +++ b/Makefile @@ -268,21 +268,34 @@ INCLUDES = . include $(GENDIR) LDFLAGS += -Llibs/$(CONFIG) ifeq ($(SYSTEM),Darwin) -LIBS += m +ifneq ($(wildcard /usr/local/ssl/include),) +INCLUDES += /usr/local/ssl/include +endif +ifneq ($(wildcard /opt/local/include),) +INCLUDES += /opt/local/include +endif +ifneq ($(wildcard /usr/local/include),) +INCLUDES += /usr/local/include +endif +LIBS = m z +ifneq ($(wildcard /usr/local/ssl/lib),) +LDFLAGS += -L/usr/local/ssl/lib +endif +ifneq ($(wildcard /opt/local/lib),) +LDFLAGS += -L/opt/local/lib +endif +ifneq ($(wildcard /usr/local/lib),) +LDFLAGS += -L/usr/local/lib +endif endif ifeq ($(SYSTEM),Linux) -LIBS += rt m pthread +LIBS = rt m z pthread LDFLAGS += -pthread endif ifeq ($(SYSTEM),MINGW32) -LIBS += m pthread -LDFLAGS += -pthread -endif - -ifeq ($(SYSTEM),FreeBSD) -LIBS += pthread +LIBS = m z pthread LDFLAGS += -pthread endif @@ -374,39 +387,6 @@ ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0-alpha-3 protobuf else # HAS_PKG_CONFIG -ifeq ($(SYSTEM),Darwin) -ifneq ($(wildcard /usr/local/ssl/include),) -INCLUDES += /usr/local/ssl/include -endif -ifneq ($(wildcard /opt/local/include),) -INCLUDES += /opt/local/include -endif -ifneq ($(wildcard /usr/local/include),) -INCLUDES += /usr/local/include -endif -ifneq ($(wildcard /usr/local/ssl/lib),) -LDFLAGS += -L/usr/local/ssl/lib -endif -ifneq ($(wildcard /opt/local/lib),) -LDFLAGS += -L/opt/local/lib -endif -ifneq ($(wildcard /usr/local/lib),) -LDFLAGS += -L/usr/local/lib -endif -endif - -ifeq ($(SYSTEM),Linux) -LIBS += z -endif - -ifeq ($(SYSTEM),MINGW32) -LIBS += z -endif - -ifeq ($(SYSTEM),FreeBSD) -LIBS += z -endif - ifeq ($(SYSTEM),MINGW32) OPENSSL_LIBS = ssl32 eay32 else diff --git a/templates/Makefile.template b/templates/Makefile.template index 2670e1b1d71..6530ea5eb23 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -282,21 +282,34 @@ INCLUDES = . include $(GENDIR) LDFLAGS += -Llibs/$(CONFIG) ifeq ($(SYSTEM),Darwin) -LIBS += m +ifneq ($(wildcard /usr/local/ssl/include),) +INCLUDES += /usr/local/ssl/include +endif +ifneq ($(wildcard /opt/local/include),) +INCLUDES += /opt/local/include +endif +ifneq ($(wildcard /usr/local/include),) +INCLUDES += /usr/local/include +endif +LIBS = m z +ifneq ($(wildcard /usr/local/ssl/lib),) +LDFLAGS += -L/usr/local/ssl/lib +endif +ifneq ($(wildcard /opt/local/lib),) +LDFLAGS += -L/opt/local/lib +endif +ifneq ($(wildcard /usr/local/lib),) +LDFLAGS += -L/usr/local/lib +endif endif ifeq ($(SYSTEM),Linux) -LIBS += rt m pthread +LIBS = rt m z pthread LDFLAGS += -pthread endif ifeq ($(SYSTEM),MINGW32) -LIBS += m pthread -LDFLAGS += -pthread -endif - -ifeq ($(SYSTEM),FreeBSD) -LIBS += pthread +LIBS = m z pthread LDFLAGS += -pthread endif @@ -399,39 +412,6 @@ ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.0.0-alpha-3 protobuf else # HAS_PKG_CONFIG -ifeq ($(SYSTEM),Darwin) -ifneq ($(wildcard /usr/local/ssl/include),) -INCLUDES += /usr/local/ssl/include -endif -ifneq ($(wildcard /opt/local/include),) -INCLUDES += /opt/local/include -endif -ifneq ($(wildcard /usr/local/include),) -INCLUDES += /usr/local/include -endif -ifneq ($(wildcard /usr/local/ssl/lib),) -LDFLAGS += -L/usr/local/ssl/lib -endif -ifneq ($(wildcard /opt/local/lib),) -LDFLAGS += -L/opt/local/lib -endif -ifneq ($(wildcard /usr/local/lib),) -LDFLAGS += -L/usr/local/lib -endif -endif - -ifeq ($(SYSTEM),Linux) -LIBS += z -endif - -ifeq ($(SYSTEM),MINGW32) -LIBS += z -endif - -ifeq ($(SYSTEM),FreeBSD) -LIBS += z -endif - ifeq ($(SYSTEM),MINGW32) OPENSSL_LIBS = ssl32 eay32 else From b62a90602b06726c807799af2340917656c02d43 Mon Sep 17 00:00:00 2001 From: yang-g Date: Wed, 5 Aug 2015 09:02:10 -0700 Subject: [PATCH 34/34] regenerate projects --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index d9ede7a6e65..c4c73db76c5 100644 --- a/Makefile +++ b/Makefile @@ -18739,7 +18739,6 @@ test/cpp/qps/timer.cc: $(OPENSSL_DEP) test/cpp/util/benchmark_config.cc: $(OPENSSL_DEP) test/cpp/util/cli_call.cc: $(OPENSSL_DEP) test/cpp/util/create_test_channel.cc: $(OPENSSL_DEP) -test/cpp/util/fake_credentials.cc: $(OPENSSL_DEP) test/cpp/util/subprocess.cc: $(OPENSSL_DEP) test/cpp/util/test_config.cc: $(OPENSSL_DEP) endif