drbrain / net-http-persistent

Thread-safe persistent connections with Net::HTTP
http://seattlerb.rubyforge.org/net-http-persistent
339 stars 117 forks source link

Expose `ConnectionPool#reload` #140

Open casperisfine opened 2 years ago

casperisfine commented 2 years ago

Ref: https://github.com/mperham/connection_pool/pull/140

When forking a process, you need to close existing connection to avoid sharing them across processes. shutdown does that, but it also mark the pool as no longer usable.

connection_pool 2.2.4 introduced #reload that discard existing connections, but let the pool be used again later. It's a much better fit for an after_fork callback.

casperisfine commented 2 years ago

Also there's kind of two schools on how to deal with this.

Some libraries insist that it's the application's job to call the proper callback on their libraries when they fork, so in this case HTTPPersistent#reload. Which I admit is cleaner, but also sometimes is hard, as the relevant object are sometimes buried deep in private variables.

Some other libraries instead add a fork detection mechanism (generally @saved_pid != Process.pid), so that they automatically discard connections after fork.

If you are open for the later, I'd be happy to provide a PR.