customerio / customerio-ruby

A ruby client for the Customer.io event API.
https://customer.io/docs/api/
MIT License
64 stars 75 forks source link

Occasional Errno::EBADF via Sidekiq. Thread-safety issues? #101

Open henrik opened 1 year ago

henrik commented 1 year ago

We've seen an Errno::EBADF: Bad file descriptor error from this lib twice in the past 3 weeks.

It runs in Sidekiq jobs (meaning it's multi-threaded). My suspicion is that it's a thread-safety issue where if two requests overlap, they might both try to close the same connection/socket causing this error.

I'm not close to expert at threading or networking so this is a complete guess.

Backtrace:

/opt/ruby/lib/ruby/3.2.0/openssl/ssl.rb:387 :in 'close'
/opt/ruby/lib/ruby/3.2.0/openssl/ssl.rb:387 :in 'sysclose'
/opt/ruby/lib/ruby/3.2.0/openssl/buffering.rb:485 in 'close'
/opt/ruby/lib/ruby/3.2.0/net/http.rb:1357 in 'rescue in connect'
/opt/ruby/lib/ruby/3.2.0/net/http.rb:1253 in 'connect'
/opt/ruby/lib/ruby/3.2.0/net/http.rb:1248 in 'do_start'
/opt/ruby/lib/ruby/3.2.0/net/http.rb:1237 :in 'start'
[GEM_ROOT]/gems/customerio-5.0.0/lib/customerio/base_client.rb:62:in 'execute'
[GEM_ROOT]/gems/customerio-5.0.0/lib/customerio/base_client.rb:28:in 'request'