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.

Request hangs with no feedback if server connection is refused

See original GitHub issue

If the server is not listening for requests and the client attempts to make a request, the client will hang with no feedback on the failed request. Reproduce by:

  1. make one basic grpc request to verify all is ok
  2. kill / stop grpc server (envoy, node proxy, etc.)
  3. attempt to make another grpc request

In the console (at least under chrome) you’ll see something similar to:

POST http://SOME_HOST/XXX/SOME_METHOD_NAME net::ERR_CONNECTION_REFUSED

The on('error'...) handler is not invoked and you have no way of knowing that the request failed.

I believe this is occurring because when XHR state is being inspected in the COMPLETE handler, the XHR status of 0 is not being checked. XHR status of 0 means that there was some problem that prevented the request from being sent (https://stackoverflow.com/questions/3825581/does-an-http-status-code-of-0-have-any-meaning/#answer-26451773)

Relevant code: https://github.com/grpc/grpc-web/blob/master/javascript/net/grpc/web/grpcwebclientreadablestream.js#L196-L214

I added a check for 0 and was then notified of the failed requests:

--- a/javascript/net/grpc/web/grpcwebclientreadablestream.js
+++ b/javascript/net/grpc/web/grpcwebclientreadablestream.js
@@ -196,7 +196,7 @@ const GrpcWebClientReadableStream = function(genericTransportInterface) {
   events.listen(this.xhr_, EventType.COMPLETE, function(e) {
     if (!self.onErrorCallback_) return;
     var lastErrorCode = self.xhr_.getLastErrorCode();
-    if (lastErrorCode != ErrorCode.NO_ERROR) {
+    if (lastErrorCode != ErrorCode.NO_ERROR || (self.xhr_.getStatus() == 0)) {
       self.onErrorCallback_({
         code: StatusCode.UNAVAILABLE,
         message: ErrorCode.getDebugMessage(lastErrorCode)

Please let me know if you want a PR or have thoughts on why my findings are invalid.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
zsluedemcommented, Oct 18, 2019

I met some similar problem like this.

I send a request to server which is down I can only get console error and not trigger the error hanler.

I think it is possible that grpc-web is only handling error from the grpc and eat all the errors in http request to the proxy.

0reactions
stanley-cheungcommented, Jul 18, 2020

This should be fixed recently. This is a unit test to show that if there’s an underlying xhr error, it should be returned as the err of the main callback. For streaming, it will be return as .on('error', ...).

Read more comments on GitHub >

github_iconTop Results From Across the Web

python3 requests hangs when accessing port 25564 or ...
Normally if a port has no server listening it will immediately refuse the connection and give a ConnectionError. Above port 25564 it doesn't...
Read more >
How to troubleshoot connectivity when curl gets an *empty ...
Try this -> Instead of going through cURL, try pinging the site you're trying to reach with Telnet. The response that your connection...
Read more >
SSH new connection begins to hang (not reject or ...
A problem can arise when you are trying to connect from behind a NAT router using OpenSSH. During session setup, after the password...
Read more >
Troubleshoot your Network Load Balancer
Connections time out for requests from a target to its load balancer. Check whether client IP preservation is enabled on your target group....
Read more >
Storage Migration Service known issues
When using Windows Admin Center to connect to a Windows Server ... Storage Migration Service times out downloading the transfer error CSV.
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