queue_classic
queue_classic copied to clipboard
207 forking in v3
Tries to fix #207
When a worker forks, the forked process inherits its master connection. Then, after the forked process is finished (exactly where I can't pinpoint), the master connection closes. At least in the test suite, the teardown function deletes all jobs, and that's when a PG::UnableToSend error pulls up.
The weird thing is that when I check the connection's status, and the connect_poll property (which ActiveRecord uses to check PG connections), they're both fine. The only way -yet- that I can tell the connection's broken is to execute and handle the PGError.
My current solution is to check the PGError for "PG::UnableToSend", and if true then reconnect and re-execute the query. I'm still hoping to find out exactly when the connection closed, without relying on an error.
I also added QC.before_fork do |worker|
and QC.after_fork do |worker, cpid|
hooks like Unicorn has, and a test to cover the connection problem and the hooks.
I updated the test to run two forked jobs in a row, and the second one will throw a PG::UnableToSend error (without the fix). That should demonstrate that it immediately disconnects, and not just on teardown. Still figuring out exactly when.
@2468ben build failing due to #212