diff --git a/packages/grpc-native-core/build.yaml b/packages/grpc-native-core/build.yaml index 49e36fdf..b5ab803f 100644 --- a/packages/grpc-native-core/build.yaml +++ b/packages/grpc-native-core/build.yaml @@ -1,2 +1,3 @@ settings: '#': It's possible to have node_version here as a key to override the core's version. + node_version: 1.16.0-pre1 diff --git a/packages/grpc-native-core/deps/grpc b/packages/grpc-native-core/deps/grpc index bc9e9ddf..98457b76 160000 --- a/packages/grpc-native-core/deps/grpc +++ b/packages/grpc-native-core/deps/grpc @@ -1 +1 @@ -Subproject commit bc9e9ddf9e04b1a905d51c41b1ffef5b30f2c986 +Subproject commit 98457b76ff43efa2c3edd203c14cd923734d5279 diff --git a/packages/grpc-native-core/src/server.js b/packages/grpc-native-core/src/server.js index b238de04..d2c9a559 100644 --- a/packages/grpc-native-core/src/server.js +++ b/packages/grpc-native-core/src/server.js @@ -52,7 +52,7 @@ function handleError(call, error) { if (error.hasOwnProperty('message')) { status.details = error.message; } - if (error.hasOwnProperty('code')) { + if (error.hasOwnProperty('code') && Number.isInteger(error.code)) { status.code = error.code; if (error.hasOwnProperty('details')) { status.details = error.details; @@ -954,6 +954,7 @@ Server.prototype.addProtoService = util.deprecate(function(service, * "address:port" * @param {grpc.ServerCredentials} creds Server credential object to be used for * SSL. Pass an insecure credentials object for an insecure port. + * @return {number} The bound port number. Negative if binding the port failed. */ Server.prototype.bind = function(port, creds) { if (this.started) { @@ -962,4 +963,32 @@ Server.prototype.bind = function(port, creds) { return this._server.addHttp2Port(port, creds); }; +/** + * Called with the result of attempting to bind a port + * @callback grpc.Server~bindCallback + * @param {Error=} error If non-null, indicates that binding the port failed. + * @param {number} port The bound port number. If binding the port fails, this + * will be negative to match the output of bind. + */ + +/** + * Binds the server to the given port, with SSL disabled if creds is an + * insecure credentials object. Provides the result asynchronously. + * @param {string} port The port that the server should bind on, in the format + * "address:port" + * @param {grpc.ServerCredentials} creds Server credential object to be used for + * SSL. Pass an insecure credentials object for an insecure port. + */ +Server.prototype.bindAsync = function(port, creds, callback) { + /* This can throw. We do not try to catch that error because it indicates an + * incorrect use of the function, which should not be surfaced asynchronously + */ + const result = this.bind(port, creds) + if (result < 0) { + setImmediate(callback, new Error('Failed to bind port'), result); + } else { + setImmediate(callback, null, result); + } +} + exports.Server = Server; diff --git a/packages/grpc-native-core/test/async_test.js b/packages/grpc-native-core/test/async_test.js index 786e50bf..119d20ce 100644 --- a/packages/grpc-native-core/test/async_test.js +++ b/packages/grpc-native-core/test/async_test.js @@ -37,14 +37,16 @@ var getServer = require('./math/math_server.js'); var server = getServer(); +let serverCreds = grpc.ServerCredentials.createInsecure(); + describe('Async functionality', function() { before(function(done) { - var port_num = server.bind('0.0.0.0:0', - grpc.ServerCredentials.createInsecure()); - server.start(); - math_client = new math.Math('localhost:' + port_num, - grpc.credentials.createInsecure()); - done(); + server.bindAsync('0.0.0.0:0', serverCreds, (error, port_num) => { + server.start(); + math_client = new math.Math('localhost:' + port_num, + grpc.credentials.createInsecure()); + done(); + }); }); after(function() { grpc.closeClient(math_client); diff --git a/packages/grpc-native-core/tools/run_tests/artifacts/build_artifact_node.bat b/packages/grpc-native-core/tools/run_tests/artifacts/build_artifact_node.bat index 85daa10b..eb8f7553 100644 --- a/packages/grpc-native-core/tools/run_tests/artifacts/build_artifact_node.bat +++ b/packages/grpc-native-core/tools/run_tests/artifacts/build_artifact_node.bat @@ -16,7 +16,7 @@ set arch_list=ia32 x64 set node_versions=4.0.0 5.0.0 6.0.0 7.0.0 8.0.0 9.0.0 10.0.0 -set electron_versions=1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 2.0.0 +set electron_versions=1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 2.0.0 3.0.0 set PATH=%PATH%;C:\Program Files\nodejs\;%APPDATA%\npm diff --git a/packages/grpc-native-core/tools/run_tests/artifacts/build_artifact_node.sh b/packages/grpc-native-core/tools/run_tests/artifacts/build_artifact_node.sh index a98c775d..d25bed84 100755 --- a/packages/grpc-native-core/tools/run_tests/artifacts/build_artifact_node.sh +++ b/packages/grpc-native-core/tools/run_tests/artifacts/build_artifact_node.sh @@ -17,7 +17,7 @@ set -ex arch_list=( ia32 x64 ) node_versions=( 4.0.0 5.0.0 6.0.0 7.0.0 8.0.0 9.0.0 10.0.0 ) -electron_versions=( 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 2.0.0 ) +electron_versions=( 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 2.0.0 3.0.0 ) while true ; do case $1 in