nahi / httpclient

'httpclient' gives something like the functionality of libwww-perl (LWP) in Ruby.
https://github.com/nahi/httpclient
703 stars 290 forks source link

Don't leave invalid sessions around if closing socket fails #411

Closed seamusabshere closed 5 years ago

seamusabshere commented 5 years ago

We use https://github.com/googleapis/google-cloud-ruby to connect to BigQuery from AWS. We have an AWS NAT in place that kills idle connections after 5 minutes. When the previous code tried to clean up old sessions, it would fail with Broken pipe on sess.close... and the invalid sessions would remain in the cache (because pool.replace was never called).

So rescuing from HTTPClient::KeepAliveDisconnected to retry it would immediately fail again, because it would use the invalid session that wasn't removed.

seamusabshere commented 5 years ago

in the meantime I am going to try to fix this with:

    sess_pool = @bigquery.service.service.client.instance_variable_get(:@session_manager).instance_variable_get(:@sess_pool)
    sess_pool.each do |_, sessions|
      sessions.each do |session|
        begin
          session.close
        rescue ::Errno::EPIPE
          $stderr.puts "Couldn't close a socket, probably killed by AWS NAT, oh well"
        end
      end
    end
    sess_pool.clear
seamusabshere commented 5 years ago

OK, no interest, closing!