Hey guys, we saw this error happen about 1000 times one fine Saturday morning and wouldn't stop until the app was restarted:
Error message Mysql2::Error: closed MySQL connection Stack trace (show Rails <https://rpm.newrelic.com/accounts/11576/applications/5786996/traced_errors/437b94e4-6161-11e6-9b5a-f8bc124250a8_47916_60425#> ) …undle/gems/sequel-4.26.0/lib/sequel/adapters/ mysql2.rb: 200:in `escape' …undle/gems/sequel-4.26.0/lib/sequel/adapters/ mysql2.rb: 200:in `block in literal_string_append' …e/gems/sequel-4.26.0/lib/sequel/database/ connecting.rb: 249:in `block in synchronize' …s/sequel-4.26.0/lib/sequel/connection_pool/ threaded.rb: 103:in `hold' …e/gems/sequel-4.26.0/lib/sequel/database/ connecting.rb: 249:in `synchronize' …undle/gems/sequel-4.26.0/lib/sequel/adapters/ mysql2.rb: 200:in `literal_string_append' …al/bundle/gems/sequel-4.26.0/lib/sequel/dataset/ sql.rb: 78:in `literal_append' …al/bundle/gems/sequel-4.26.0/lib/sequel/dataset/ sql.rb: 485:in `complex_expression_sql_append' …gems/sequel-4.26.0/lib/sequel/adapters/shared/ mysql.rb: 653:in `complex_expression_sql_append' …le/gems/sequel-4.26.0/lib/sequel/model/ associations.rb:2492:in `complex_expression_sql_append' /usr/local/bundle/gems/sequel-4.26.0/lib/sequel/ sql.rb: 107:in `to_s_append' …al/bundle/gems/sequel-4.26.0/lib/sequel/dataset/ sql.rb:1207:in `literal_expression_append' …al/bundle/gems/sequel-4.26.0/lib/sequel/dataset/ sql.rb: 85:in `literal_append' …al/bundle/gems/sequel-4.26.0/lib/sequel/dataset/ sql.rb: 493:in `block in complex_expression_sql_append' …al/bundle/gems/sequel-4.26.0/lib/sequel/dataset/ sql.rb: 491:in `each' …al/bundle/gems/sequel-4.26.0/lib/sequel/dataset/ sql.rb: 491:in `complex_expression_sql_append' …gems/sequel-4.26.0/lib/sequel/adapters/shared/ mysql.rb: 653:in `complex_expression_sql_append' …le/gems/sequel-4.26.0/lib/sequel/model/ associations.rb:2492:in `complex_expression_sql_append' /usr/local/bundle/gems/sequel-4.26.0/lib/sequel/ sql.rb: 107:in `to_s_append' …al/bundle/gems/sequel-4.26.0/lib/sequel/dataset/ sql.rb:1207:in `literal_expression_append' …al/bundle/gems/sequel-4.26.0/lib/sequel/dataset/ sql.rb: 85:in `literal_append' …al/bundle/gems/sequel-4.26.0/lib/sequel/dataset/ sql.rb:1448:in `select_where_sql' …al/bundle/gems/sequel-4.26.0/lib/sequel/dataset/ sql.rb: 230:in `select_sql' …undle/gems/sequel-4.26.0/lib/sequel/dataset/ actions.rb: 137:in `each' /webapps/app/pagination/concerns/ model_pagination.rb: 32:in `to_a' /webapps/app/pagination/concerns/ model_pagination.rb: 32:in `load_models!' It seems that this error is not being caught or handled and the closed connections are remaining in the pool. Looking at the code, in the connection_pool/threaded.rb: def hold(server=nil) t = Thread.current if conn = owned_connection(t) return yield(conn) end begin conn = acquire(t) yield conn rescue Sequel::DatabaseDisconnectError, *@error_classes => e if disconnect_error?(e) oconn = conn conn = nil disconnect_connection(oconn) if oconn @allocated.delete(t) end raise ensure sync{release(t)} if conn end end It seems like this could be fixed by moving the first yield call to inside the begin block. I'm not clear on why it specifically bypasses the error handling for stale connections. I was going to make a pull request, but I wanted to make sure my understanding of the issue was correct first. Agree/disagree?James -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
