spdy-http2 / node-spdy

SPDY server on Node.js
2.81k stars 196 forks source link

Got "Can't send request after GOAWAY" error #278

Open richardkazuomiller opened 8 years ago

richardkazuomiller commented 8 years ago

I'm making requests using spdy@3.4.2 to make requests to an HTTP2 server (Google Cloud Load Balancing) and the error Can't send request after GOAWAY was thrown and the process crashed.

How can I handle this so the client can make a new connection when the server wants it to "go away"? Is there some kind of GOAWAY event fired so I can create a new agent or something?

richardkazuomiller commented 8 years ago

I did some digging and found that spdyAgent._spdyState.connection._spdyState.goaway is a thing. If that's truthy !== false, I create a new agent before making a request, and that seems to make things better. Does that make sense? I'm not super familiar with the details of the h2 spec.

I think reconnection should either be done automatically by the agent or there should be a more obvious way to figure out if an agent needs to reconnect.

richardkazuomiller commented 8 years ago

Update in case anyone reads this and uses my solution:

_spdyState.goaway can sometimes be 0 if GOAWAY is the first thing it receives so checking if goaway is truthy is not good enough – it must be not false.