question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Error: 14 UNAVAILABLE: Stream refused by server"

See original GitHub issue

Problem description

image

syntax = "proto3";

package messager;

service Messager {
  rpc getInfo(Request) returns (Reply){}
}

message Reply {
  string raw = 1;
}

message Request {
  string raw = 1;
}
// server.js
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const path = require('path')

let packageDefinition = protoLoader.loadSync(
    path.join(__dirname, 'messager.proto'),
    {
        keepCase: true,
        longs: String,
        enums: String,
        defaults: true,
        oneofs: true
    });
let messager = grpc.loadPackageDefinition(packageDefinition).messager;
let server = new grpc.Server();
server.addService(messager.Messager.service, {
    getInfo: (call, callback) => {
        callback(null, { raw: 'This is server' });
    }
});
server.bindAsync('0.0.0.0:3000', grpc.ServerCredentials.createInsecure(), (err, port) => {
    if (err) {
        console.log(err);
    } else {
        console.log('GRPC server binding on port: ' + port);
    }
});
// client.js
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const path = require('path')

let packageDefinition = protoLoader.loadSync(
    path.join(__dirname, 'messager.proto'),
    {
        keepCase: true,
        longs: String,
        enums: String,
        defaults: true,
        oneofs: true
    });
let messager = grpc.loadPackageDefinition(packageDefinition).messager;
let client = new messager.Messager('0.0.0.0:3000', grpc.credentials.createInsecure());
client.getInfo({}, (err, reply) => {
    if (err) {
        console.log(err);
    } else {
        console.log(reply);
    }
})

Environment

  • OS name: Ubuntu 19.10, version and architecture: [Linux Ubuntu 19.10 amd64]
  • Node version: v12.16.1
  • Package name and version: “@grpc/grpc-js”: “^1.0.3”, “@grpc/proto-loader”: “^0.5.4”,

Full Error

Error: 14 UNAVAILABLE: Stream refused by server
    at Object.callErrorFromStatus (/Research/grpcjs/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
    at Object.onReceiveStatus (/Research/grpcjs/node_modules/@grpc/grpc-js/build/src/client.js:175:52)
    at Object.onReceiveStatus (/Research/grpcjs/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:341:141)
    at Object.onReceiveStatus (/Research/grpcjs/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:304:181)
    at Http2CallStream.outputStatus (/Research/grpcjs/node_modules/@grpc/grpc-js/build/src/call-stream.js:115:74)
    at Http2CallStream.maybeOutputStatus (/Research/grpcjs/node_modules/@grpc/grpc-js/build/src/call-stream.js:154:22)
    at Http2CallStream.endCall (/Research/grpcjs/node_modules/@grpc/grpc-js/build/src/call-stream.js:140:18)
    at ClientHttp2Stream.<anonymous> (/Research/grpcjs/node_modules/@grpc/grpc-js/build/src/call-stream.js:396:22)
    at ClientHttp2Stream.emit (events.js:311:20)
    at emitCloseNT (internal/streams/destroy.js:69:8) {
  code: 14,
  details: 'Stream refused by server',
  metadata: Metadata { internalRepr: Map {}, options: {} }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
nnthuaneganycommented, Sep 7, 2020

Hi @dooleyb1 This problem happened because the “server” instance call server.start(); outside the callback when bindAsync.

So just starting the server in the callback solves the problem. It looks like this

//server.js
server.bindAsync(`${config.address}:${config.port}`, grpc.ServerCredentials.createInsecure(),  (err, port) => {
  if (err) {
    logger.log(err);
    process.exit(1);
  } else {
    server.start(); //here
    logger.info(`Address: ${config.address}`);
    logger.info(`Port: ${port}`);
  }
});
0reactions
nnthuaneganycommented, Nov 16, 2021

Hi @lwmxiaobei, maybe your case is a different problem than mine. I also read some similar problems caused by setup “credentials”

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: 14 UNAVAILABLE: Stream refused by server #1969
The server may refuse to serve new requests if it is already handling too many other requests. This is normal behavior. Your client...
Read more >
Stream refused by server. Create BigTable client per-request ...
Persistently receiving 14 UNAVAILABLE: Stream refused by server. Create BigTable client per-request? Ask Question. Asked 1 year, 7 months ago.
Read more >
GRPC Core: Status codes and their use in gRPC
Code Number Description OK 0 Not an error; returned on success. FAILED_PRECONDITION 9 OUT_OF_RANGE 11
Read more >
grpc/grpc - Gitter
A Kotlin grpc server running within aws ECS and fronted by an aws ALB set up to load balance ... Error: 14 UNAVAILABLE:...
Read more >
Troubleshooting Response Errors | Cloud Endpoints with gRPC
If you receive error code 14 and the message upstream backend unavailable , this indicates that the Extensible Service Proxy (ESP) can't reach...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found