Redth / HttpTwo

A basic C# HTTP/2 client library
Apache License 2.0
120 stars 51 forks source link

Server sends GOAWAY frame with ProtocoleError as error and message: First received frame was not SETTINGS. #8

Open huycn opened 7 years ago

huycn commented 7 years ago

What happens is that when we let the HTTP2Client idle for while (few min) and then post a new request, we receives immediately a SETTINGS frame for which the client replies with another SETTINGS frame with Ack=True before sending another SETTINGS (Ack=false) frame which is part of new request. In such case the server will terminate the connection with a GOAWAY frame as follow:

<- [Frame: SETTINGS, Id=0, Ack=False, ...] -> [Frame: SETTINGS, Id=0, Ack=True, ...] -> [Frame: SETTINGS, Id=0, Ack=False, ...] -> [Frame: HEADERS, Id=15, ...] -> [Frame: DATA, Id=15, ...] <- [Frame: GOAWAY, Id=0, ErrorCode=1, LastStreamId=0, AdditionalDebugData=First received frame was not SETTINGS. Hex dump for first 5 bytes: 0000000401]

For now, to workaround this issue, I insert an await Task.Delay(50) before queuing acknowledge frame, that is in Http2Connection.read() line 129, if (!settingsFrame.Ack) { await Task.Delay(50); // this is inserted line await QueueFrame(new SettingsFrame { Ack = true }).ConfigureAwait(false); } and the issue above will not happen.

However, I see this modif is more a hack than a fix. I wonder if someone could fix this problem at its root.

Thanks.

Neio commented 7 years ago

This happened because it is sending message to wrong TCP connection somethings. I have some fixes in my fork.