Request hangs with no feedback if server connection is refused
See original GitHub issueIf 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:
- make one basic grpc request to verify all is ok
- kill / stop grpc server (envoy, node proxy, etc.)
- 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:
- Created 5 years ago
- Reactions:2
- Comments:9 (1 by maintainers)
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.
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', ...)
.