Last active
July 26, 2018 23:38
-
-
Save drobertduke/2defdc912f61fee8e28900d7449a0d4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| This is an alternate version of the example client in | |
| https://github.com/grpc/grpc/blob/master/examples/node/dynamic_codegen/greeter_client.js | |
| that reproduces issue #15933. | |
| Repro steps: | |
| $ cd grpc/examples/node/dynamic_codegen | |
| $ npm install | |
| $ npm install grpc@1.11.3 | |
| $ node greeter_server.js & | |
| $ node greeter_client.js # note no errors occur on 1.11.3 | |
| $ npm install grpc@1.12.1 | |
| $ node greeter_client.js # note "Failed to create subchannel" errors | |
| */ | |
| var PROTO_PATH = __dirname + '/../../protos/helloworld.proto'; | |
| var grpc = require('grpc'); | |
| var hello_proto = grpc.load(PROTO_PATH).helloworld; | |
| var readline = require('readline'); | |
| var rl = readline.createInterface({ | |
| input: process.stdin, | |
| output: process.stdout, | |
| terminal: false | |
| }); | |
| function newClient() { | |
| return new hello_proto.Greeter( | |
| 'localhost:50051', // greeter_server.js must already be running | |
| grpc.credentials.createInsecure(), | |
| {'grpc.lb_policy_name': 'round_robin'}, // Removing this line eliminates the issue! | |
| ); | |
| } | |
| function main() { | |
| let client, numResponses = 0, numRequests = 0; | |
| function newRequest(makeClient) { | |
| if (makeClient) { | |
| client = newClient(); | |
| } | |
| numRequests++; | |
| client.sayHello({name: numRequests.toString()}, function(err, resp) { | |
| numResponses++; | |
| if (err) { | |
| console.log(`Error: ${err.message}`); | |
| } else { | |
| console.log(`Response ${resp.message}`); | |
| } | |
| }); | |
| console.log(`Request ${numRequests}`); | |
| } | |
| newRequest(true); | |
| rl.on('line', function(line){ | |
| const makeClient = line.startsWith('n'); | |
| newRequest(makeClient); | |
| }); | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment