resque icon indicating copy to clipboard operation
resque copied to clipboard

unexpected EOF on client connection

Open gravis opened this issue 15 years ago • 38 comments

Hello,

we have noticed a lot of :

2011-08-24 15:24:00 CEST LOG:  could not receive data from client: Connection reset by peer
2011-08-24 15:24:00 CEST LOG:  unexpected EOF on client connection

in our log. After some digging, the disconnections are coming from resque. Sounds like everytime a job is done, the worker doesn't close nicely the connection.

This issue is related to #306 : we have to establish a connection on forking. I've tried to disconnect cleanly in done_working, but the working is dying when doing that. Any idea ?

gravis avatar Aug 24 '11 13:08 gravis

I was running into the same issue on Heroku and wrote a gem to fix it. Disconnecting from the db in Worker#done_working didn't work for me either, but it does work in an after_perform callback in the job. The reason is because after_perform is called inside the thread where done_working is back in the parent process.

Here's the gem... https://github.com/simple10/resque-heroku

No more "unexpected EOF on client connection" after installing it.

simple10 avatar Sep 12 '11 15:09 simple10

@simple10 you say in the read me it's a Cedar centered fix, do you know if it also works with bamboo apps ?

mcansky avatar Apr 05 '12 16:04 mcansky

It should work with bamboo with some minor modifications. I forget which are the Cedar bits right off hand.

simple10 avatar Apr 17 '12 00:04 simple10

I'm also seeing this with heroku and python.

desimone avatar Aug 21 '12 01:08 desimone

Without a way to reproduce this, it's not likely we can fix it. I'm going to close, but if someone can provide a reproduction, let's re-open.

steveklabnik avatar Sep 27 '12 19:09 steveklabnik

Was this resolved? I see a lot of these error on Heroku Cedar stack using resque with redistogo. The gem by simple10 did not resolve for me.

marclennox avatar Oct 06 '12 14:10 marclennox

If you can give me a small app that reproduces the problem, I can re-open and take a look at it. But without a way of seeing the error, there's no way I can try to fix it.

steveklabnik avatar Oct 06 '12 16:10 steveklabnik

understood.

Marc Lennox Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Saturday, 6 October, 2012 at 12:24 PM, Steve Klabnik wrote:

If you can give me a small app that reproduces the problem, I can re-open and take a look at it. But without a way of seeing the error, there's no way I can try to fix it.

— Reply to this email directly or view it on GitHub (https://github.com/defunkt/resque/issues/367#issuecomment-9199610).

marclennox avatar Oct 06 '12 16:10 marclennox

I do have a Heroku account, so that's not a barrier. Does this always happen, or is it triggered by something?

steveklabnik avatar Oct 06 '12 16:10 steveklabnik

I'm pretty sure it's 100% because my Heroku log is filled with them constantly. Here's a sample.

2012-10-06T16:40:07+00:00 app[postgres]: [6-1] ub8f56dr4dsefv [IVORY] LOG: unexpected EOF on client connection 2012-10-06T16:40:07+00:00 app[postgres]: [6-1] ub8f56dr4dsefv [IVORY] LOG: unexpected EOF on client connection 2012-10-06T16:40:07+00:00 app[postgres]: [5-1] ub8f56dr4dsefv [IVORY] LOG: could not receive data from client: Connection reset by peer 2012-10-06T16:40:07+00:00 app[postgres]: [6-1] ub8f56dr4dsefv [IVORY] LOG: unexpected EOF on client connection 2012-10-06T16:40:07+00:00 app[postgres]: [5-1] ub8f56dr4dsefv [IVORY] LOG: could not receive data from client: Connection reset by peer 2012-10-06T16:40:08+00:00 heroku[api]: Deploy a3b8cc5 by [email protected] 2012-10-06T16:40:08+00:00 heroku[api]: Release v496 created by [email protected] 2012-10-06T16:40:08+00:00 heroku[web.1]: State changed from up to starting 2012-10-06T16:40:09+00:00 heroku[slugc]: Slug compilation finished 2012-10-06T16:40:09+00:00 app[postgres]: [6-1] ub8f56dr4dsefv [IVORY] LOG: unexpected EOF on client connection 2012-10-06T16:40:09+00:00 app[postgres]: [5-1] ub8f56dr4dsefv [IVORY] LOG: could not receive data from client: Connection reset by peer 2012-10-06T16:40:10+00:00 heroku[web.1]: State changed from starting to up 2012-10-06T16:40:10+00:00 heroku[web.1]: State changed from up to starting 2012-10-06T16:40:12+00:00 heroku[web.1]: Stopping all processes with SIGTERM 2012-10-06T16:40:13+00:00 app[postgres]: [5-1] ub8f56dr4dsefv [IVORY] LOG: could not receive data from client: Connection reset by peer 2012-10-06T16:40:13+00:00 app[postgres]: [6-1] ub8f56dr4dsefv [IVORY] LOG: unexpected EOF on client connection 2012-10-06T16:40:13+00:00 app[web.1]: I, [2012-10-06T16:40:13.624193 #2] INFO -- : reaped #<Process::Status: pid 16 exit 0> worker=1 2012-10-06T16:40:15+00:00 app[postgres]: [5-1] ub8f56dr4dsefv [IVORY] LOG: could not receive data from client: Connection reset by peer 2012-10-06T16:40:15+00:00 app[postgres]: [5-1] ub8f56dr4dsefv [IVORY] LOG: could not receive data from client: Connection reset by peer 2012-10-06T16:40:15+00:00 app[postgres]: [6-1] ub8f56dr4dsefv [IVORY] LOG: unexpected EOF on client connection 2012-10-06T16:40:15+00:00 app[postgres]: [6-1] ub8f56dr4dsefv [IVORY] LOG: unexpected EOF on client connection 2012-10-06T16:40:15+00:00 app[web.1]: I, [2012-10-06T16:40:15.165541 #2] INFO -- : reaped #<Process::Status: pid 13 exit 0> worker=0 2012-10-06T16:40:15+00:00 app[web.1]: I, [2012-10-06T16:40:15.174977 #2] INFO -- : master complete 2012-10-06T16:40:15+00:00 app[web.1]: I, [2012-10-06T16:40:15.165750 #2] INFO -- : reaped #<Process::Status: pid 19 exit 0> worker=2 2012-10-06T16:40:16+00:00 heroku[web.1]: Process exited with status 0 2012-10-06T16:40:16+00:00 heroku[web.1]: Starting process with command bundle exec unicorn -p 39951 -c ./config/unicorn.rb 2012-10-06T16:40:18+00:00 app[web.1]: I, [2012-10-06T16:40:18.646990 #2] INFO -- : listening on addr=0.0.0.0:39951 fd=7 2012-10-06T16:40:18+00:00 app[web.1]: I, [2012-10-06T16:40:18.647338 #2] INFO -- : worker=0 spawning... 2012-10-06T16:40:18+00:00 app[web.1]: I, [2012-10-06T16:40:18.653235 #13] INFO -- : Refreshing Gem list 2012-10-06T16:40:18+00:00 app[web.1]: I, [2012-10-06T16:40:18.652197 #2] INFO -- : worker=1 spawning... 2012-10-06T16:40:18+00:00 app[web.1]: I, [2012-10-06T16:40:18.652973 #13] INFO -- : worker=0 spawned pid=13 2012-10-06T16:40:18+00:00 app[web.1]: I, [2012-10-06T16:40:18.654731 #2] INFO -- : worker=2 spawning... 2012-10-06T16:40:18+00:00 app[web.1]: I, [2012-10-06T16:40:18.655701 #16] INFO -- : worker=1 spawned pid=16 2012-10-06T16:40:18+00:00 app[web.1]: I, [2012-10-06T16:40:18.655977 #16] INFO -- : Refreshing Gem list 2012-10-06T16:40:18+00:00 app[web.1]: I, [2012-10-06T16:40:18.657573 #2] INFO -- : master process ready 2012-10-06T16:40:18+00:00 app[web.1]: I, [2012-10-06T16:40:18.658206 #19] INFO -- : worker=2 spawned pid=19 2012-10-06T16:40:18+00:00 app[web.1]: I, [2012-10-06T16:40:18.658394 #19] INFO -- : Refreshing Gem list 2012-10-06T16:40:19+00:00 heroku[web.1]: State changed from starting to up 2012-10-06T16:40:20+00:00 heroku[web.1]: Starting process with command bundle exec unicorn -p 13025 -c ./config/unicorn.rb 2012-10-06T16:40:22+00:00 app[web.1]: I, [2012-10-06T16:40:22.985838 #2] INFO -- : worker=1 spawning... 2012-10-06T16:40:22+00:00 app[web.1]: I, [2012-10-06T16:40:22.986871 #13] INFO -- : Refreshing Gem list 2012-10-06T16:40:22+00:00 app[web.1]: I, [2012-10-06T16:40:22.980781 #2] INFO -- : listening on addr=0.0.0.0:13025 fd=7 2012-10-06T16:40:22+00:00 app[web.1]: I, [2012-10-06T16:40:22.990788 #16] INFO -- : worker=1 spawned pid=16 2012-10-06T16:40:22+00:00 app[web.1]: I, [2012-10-06T16:40:22.981063 #2] INFO -- : worker=0 spawning... 2012-10-06T16:40:22+00:00 app[web.1]: I, [2012-10-06T16:40:22.991039 #16] INFO -- : Refreshing Gem list 2012-10-06T16:40:22+00:00 app[web.1]: I, [2012-10-06T16:40:22.986636 #13] INFO -- : worker=0 spawned pid=13 2012-10-06T16:40:22+00:00 app[web.1]: I, [2012-10-06T16:40:22.991952 #19] INFO -- : worker=2 spawned pid=19 2012-10-06T16:40:22+00:00 app[web.1]: I, [2012-10-06T16:40:22.988712 #2] INFO -- : worker=2 spawning... 2012-10-06T16:40:22+00:00 app[web.1]: I, [2012-10-06T16:40:22.991008 #2] INFO -- : master process ready 2012-10-06T16:40:22+00:00 app[web.1]: I, [2012-10-06T16:40:22.992165 #19] INFO -- : Refreshing Gem list 2012-10-06T16:40:27+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 2012-10-06T16:40:27+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 2012-10-06T16:40:27+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 2012-10-06T16:40:27+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 2012-10-06T16:40:27+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 2012-10-06T16:40:27+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 2012-10-06T16:40:28+00:00 heroku[web.1]: Stopping all processes with SIGTERM 2012-10-06T16:40:28+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:28 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (13)] INFO : New Relic Ruby Agent 3.4.2.1 Initialized: pid = 13 2012-10-06T16:40:28+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:28 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (13)] INFO : Application: openera-production 2012-10-06T16:40:28+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:28 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (13)] INFO : Dispatcher: thin 2012-10-06T16:40:28+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:28 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (19)] INFO : Dispatcher: thin 2012-10-06T16:40:28+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:28 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (19)] INFO : New Relic Ruby Agent 3.4.2.1 Initialized: pid = 19 2012-10-06T16:40:28+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:28 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (19)] INFO : Application: openera-production 2012-10-06T16:40:28+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:28 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (16)] INFO : Dispatcher: thin 2012-10-06T16:40:28+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:28 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (16)] INFO : New Relic Ruby Agent 3.4.2.1 Initialized: pid = 16 2012-10-06T16:40:28+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:28 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (16)] INFO : Application: openera-production 2012-10-06T16:40:29+00:00 app[web.1]: I, [2012-10-06T16:40:29.001895 #2] INFO -- : reaped #<Process::Status: pid 13 exit 0> worker=0 2012-10-06T16:40:29+00:00 app[web.1]: I, [2012-10-06T16:40:29.110291 #2] INFO -- : reaped #<Process::Status: pid 16 exit 0> worker=1 2012-10-06T16:40:29+00:00 app[web.1]: I, [2012-10-06T16:40:29.110425 #2] INFO -- : reaped #<Process::Status: pid 19 exit 0> worker=2 2012-10-06T16:40:29+00:00 app[web.1]: I, [2012-10-06T16:40:29.110559 #2] INFO -- : master complete 2012-10-06T16:40:30+00:00 heroku[deployhooks]: Notified New Relic about the deploy 2012-10-06T16:40:30+00:00 heroku[web.1]: Process exited with status 0 2012-10-06T16:40:34+00:00 app[postgres]: [5-1] ub8f56dr4dsefv [IVORY] LOG: duration: 55.424 ms statement: SELECT "file_actions".* FROM "file_actions" WHERE (current_state NOT IN ('')) AND (started_at IS NOT NULL) AND (ended_at IS NULL) AND (now() > started_at + (300 * interval '1 second')) 2012-10-06T16:40:34+00:00 app[postgres]: [6-1] ub8f56dr4dsefv [IVORY] LOG: duration: 61.879 ms statement: SELECT "file_actions".* FROM "file_actions" WHERE (current_state NOT IN ('executing', 'processed')) AND (now() > next_at) 2012-10-06T16:40:34+00:00 app[postgres]: [7-1] ub8f56dr4dsefv [IVORY] LOG: could not receive data from client: Connection reset by peer 2012-10-06T16:40:34+00:00 app[postgres]: [8-1] ub8f56dr4dsefv [IVORY] LOG: unexpected EOF on client connection 2012-10-06T16:40:35+00:00 app[postgres]: [5-1] ub8f56dr4dsefv [IVORY] LOG: could not receive data from client: Connection reset by peer 2012-10-06T16:40:35+00:00 app[postgres]: [6-1] ub8f56dr4dsefv [IVORY] LOG: unexpected EOF on client connection 2012-10-06T16:40:37+00:00 app[web.1]: I, [2012-10-06T16:40:37.605326 #19] INFO -- : worker=2 ready 2012-10-06T16:40:37+00:00 app[web.1]: I, [2012-10-06T16:40:37.614676 #13] INFO -- : worker=0 ready 2012-10-06T16:40:37+00:00 app[web.1]: I, [2012-10-06T16:40:37.684254 #16] INFO -- : worker=1 ready 2012-10-06T16:40:39+00:00 app[web.1]: Connected to NewRelic Service at collector-9.newrelic.com 2012-10-06T16:40:39+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:39 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (13)] INFO : Reporting performance data every 60 seconds. 2012-10-06T16:40:39+00:00 app[web.1]: Connected to NewRelic Service at collector-9.newrelic.com 2012-10-06T16:40:39+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:39 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (19)] INFO : Reporting performance data every 60 seconds. 2012-10-06T16:40:39+00:00 app[web.1]: Connected to NewRelic Service at collector-9.newrelic.com 2012-10-06T16:40:39+00:00 app[web.1]: ** [NewRelic][10/06/12 16:40:39 +0000 ab387c93-27c3-4aff-b270-cec34a8fdad6 (16)] INFO : Reporting performance data every 60 seconds.

Marc Lennox Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Saturday, 6 October, 2012 at 12:39 PM, Steve Klabnik wrote:

I do have a Heroku account, so that's not a barrier. Does this always happen, or is it triggered by something?

— Reply to this email directly or view it on GitHub (https://github.com/defunkt/resque/issues/367#issuecomment-9199781).

marclennox avatar Oct 06 '12 16:10 marclennox

I've re-opened this. I'm travelling for a few days, but on Monday I'll attempt to get an app that reproduces this. If you can get one up earlier, then I can get started fixing it earlier :)

steveklabnik avatar Oct 06 '12 16:10 steveklabnik

Thanks Steve, I'll see what I can do. I'm assuming this is not universal, so probably there's something unique about the environment that contributes to this.

Marc Lennox Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Saturday, 6 October, 2012 at 12:51 PM, Steve Klabnik wrote:

I've re-opened this. I'm travelling for a few days, but on Monday I'll attempt to get an app that reproduces this. If you can get one up earlier, then I can get started fixing it earlier :)

— Reply to this email directly or view it on GitHub (https://github.com/defunkt/resque/issues/367#issuecomment-9199899).

marclennox avatar Oct 06 '12 17:10 marclennox

Hey we're experiencing this with Minefold on Heroku too. Happy to share our code-base to help diagnose the problem.

chrislloyd avatar Dec 03 '12 22:12 chrislloyd

Hey Chris,

Steve is looking for a simple heroku app that replicates the problem and that he can debug with. It's been on my "to do" list for a while now, but haven't got around to it.

marclennox avatar Dec 03 '12 23:12 marclennox

Ran into this today using the combination of Heroku (Cedar) + Sequel + Resque. The heroku-resque gem by @simple10 is not a workaround for us as it's for ActiveRecord.

I'll attempt to sidestep my "to do" list (i.e. /dev/null) and package a small app that reproduces the problem.

DevL avatar Dec 04 '12 15:12 DevL

I've updated the README for my gem to make it clear it only works with ActiveRecord.

simple10 avatar Dec 04 '12 18:12 simple10

FWIW, we tried the heroku-resque gem - we use ActiveRecord - and we were still seing said EOF. If I can I'd like to help with the issue.

carhartl avatar Dec 04 '12 20:12 carhartl

Yeah the heroku-resque gem doesn't do anything for me either.

Marc Lennox Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Tuesday, 4 December, 2012 at 3:03 PM, Klaus Hartl wrote:

FWIW, we tried the heroku-resque gem - we use ActiveRecord - and we were still seing said EOF. If I can I'd like to help with the issue.

— Reply to this email directly or view it on GitHub (https://github.com/defunkt/resque/issues/367#issuecomment-11013313).

marclennox avatar Dec 04 '12 21:12 marclennox

Well, after doing some more digging this certainly doesn't feel as a Resque issue.

Since Resque forks workers, placing any and all handling of the database in e.g. the perform method will make this issue go away. However, it does raise the following question:

Given the case of a worker fetching jobs from Redis and storing something in e.g. a Postgres database, is it necessary to constantly open and close database connections rather than somehow keeping a connection pool around?

To my understanding, the answer is 'yes', but please correct me if I'm wrong.

Sidenote: Given this particular use case, Sidekiq might be a better fit as it's based on threads rather than forks?

DevL avatar Dec 05 '12 10:12 DevL

So I'm having similar (but different) EOF errors on Heroku. I fully detailed it in a StackOverflow post.

http://stackoverflow.com/questions/14114405/resque-worker-causing-activerecordstatementinvalid-pgerror-ssl-syscall-err

Tried about everything under the run, without luck. Happening on two separate apps. Going to try that gem fix and report back.

tibbon avatar Jan 01 '13 22:01 tibbon