haskell-grpc-native / http2-client

A native HTTP2 client in Haskell
BSD 3-Clause "New" or "Revised" License
43 stars 27 forks source link

Fix observing base window size in initHttp2Client #68

Closed TravisWhitaker closed 5 years ago

TravisWhitaker commented 5 years ago

This fixes a bug which could cause _withdrawCredit from a connection's OutgoingFlowControl to spin forever. Without this patch, getBase in newOutgoingFlowControl would always return the default initial window size, even if we had received an updated window size from the server. If the server sets an initial window size not equal to the default, waitSettingsChange would almost always win the race against waitSomeCredit, causing withdraw to spin forever.

The current definition of withdraw is still problematic, consider this ordering:

With this patch this bad ordering should be exceedingly rare; without this patch, it happens almost every time we run out of outgoing credit!

lucasdicioccio commented 5 years ago

Oh you're right. I feel like it was a monadic effect for some reason and never got to implement it entirely! Thanks, this patch is much appreciated.

Can you open another issue for the potential race conditions + if you have some time and ideas on how to improve it. I'll be on a trip soon and won't have much time before end of May.