tansengming / stripe-rails

A Rails Engine for integrating with Stripe
MIT License
753 stars 123 forks source link

ERRO Request error error_message="closed stream" method=get path=/v1/payment_methods #193

Open AlanMcCann opened 4 years ago

AlanMcCann commented 4 years ago

Versions stripe-rails: 1.10.1 stripe: 5.22.0 ruby 2.6.3

After starting the rails app, I can issue successful requests one after another. If I pause for a minute and then try again, I get a message as follows

irb(main):028:0> Stripe::PaymentMethod.list({customer: "cus_xxxxxxxxxxxxxxxx", type: "card"})
INFO Request to Stripe API api_version=2019-12-03 method=get num_retries=0 path=/v1/payment_methods
ERRO Request error elapsed=0.03208500000619097 error_message="closed stream" method=get path=/v1/payment_methods

This happens with any method

This doesn't happen with the plain stripe gem.

I have tried creating a new client for each request and that has the same issue

client = Stripe::StripeClient.new
payment_methods, resp = client.request do
  Stripe::PaymentMethod.list({
    customer: "cus_xxxxxxxxxxxx",
    type: 'card',
    limit: 100
  }, $STRIPE_REQUEST_CREDENTIALS[:non_profit])
end

Any thoughts? Thanks!

tansengming commented 3 years ago

Did you manage to figure this out?

I just tried it out from a minimal rails install at https://github.com/tansengming/stripe-rails-dummy/tree/8da724014c48633f6ba48ca96fb0421728718eba and could not reproduce it.

As far as I know the app does not mess with the http client so I don't think the gem is causing this. I'd look into https://github.com/stripe/stripe-ruby/blob/0620436d63a40af8bdc93057c1cdb4e58bf1a30a/lib/stripe/stripe_client.rb to see how the stripe gem is handling closed streams.

Good luck!