Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql::Error: Lost connection to MySQL server during query #86

Open
maxig opened this issue Nov 14, 2013 · 3 comments
Open

Mysql::Error: Lost connection to MySQL server during query #86

maxig opened this issue Nov 14, 2013 · 3 comments

Comments

@maxig
Copy link

maxig commented Nov 14, 2013

Hi.
Parallel.map(orders, :in_processes => 6) do |order|
ActiveRecord::Base.establish_connection
# some huge calculation
end

And i get this error:
Mysql::Error: Lost connection to MySQL server during query

or this one:
Mysql::Error: MySQL server has gone away

What i did wrong?

@grosser
Copy link
Owner

grosser commented Nov 15, 2013

Nothing, AR + forking = fooo, if you find a reliable method let me know... (maybe rescue reconnect..., I don't know...)

@wilsonmichael
Copy link

What has worked for me is calling ActiveRecord::Base.connection.reconnect! inside the block

Parallel.each( items, in_processes: 4 ) do |item|
  # Reconnect to the database in the new process ( or thread )
  ActiveRecord::Base.connection.reconnect!
  # do stuff ...
end

@grosser
Copy link
Owner

grosser commented Dec 11, 2013

did this work too ? (would lower the amount of reconnects)

  @reconnected ||= User.connection.reconnect! || true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@grosser @maxig @wilsonmichael and others