ostinelli / net-http2

NetHttp2 is an HTTP/2 client for Ruby.
MIT License
141 stars 31 forks source link

HTTP2::Error::StreamLimitExceeded when using request timeouts #31

Open sidonath opened 6 years ago

sidonath commented 6 years ago

Hi there and thanks for providing and maintaining an HTTP2 client and a modern Ruby client for push notifications 🙇

I'm implementing the push notifications with Apnotic right now, and as I was testing how the app behaves when a timeout occurs I noticed a rather strange issue.

I have a loop set up to attempt 3 deliveries in case of a timeout, something like this:

1.upto(MAX_ATTEMPTS) do
  response = @connection.push(notification, timeout: 0.1)
  break if response
end

I set timeout intentionally to a very low value, to test for the failure. However, when the loop runs for the second time, I get the following:

HTTP2::Error::StreamLimitExceeded: HTTP2::Error::StreamLimitExceeded
from /var/lib/gems/2.5.0/gems/http-2-0.9.0/lib/http/2/connection.rb:107:in `new_stream'

This happens when trying to send a single notification from my machine. If I add sleep 0.3 I can count on the loop running 3 times. If I remove timeout option, I can seemingly send as many notifications as I want.

This makes me assume it's something specific to how handling the timeout is implemented. That's why I'm posting it here and not directly in Apnotic.

Maybe the issue is that the timeout is so low, that the stream somehow gets corrupted and the lower value of timeout should be restricted somehow? Or that releasing the lock to soon in Stream#wait_for_completed doesn't do a proper clean-up?

I can easily reproduce this locally and will be happy to help debugging!