Unexpected Database Connection with wrong credentials when using sentry-rails
Issue Description
Using
# config/initializers/sentry.rb
Sentry.init do |config|
config.dsn = 'https://…' unless Rails.env.test?
config.breadcrumbs_logger = [:active_support_logger, :http_logger]
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for tracing.
# We recommend adjusting this value in production.
config.traces_sample_rate = 1.0
# or
# config.traces_sampler = lambda do |_context|
# true
# end
# Set profiles_sample_rate to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
config.profiles_sample_rate = 1.0
end
and starting the app (rails s) we suddenly got
Host '10.0.0.1' is blocked because of many connection errors; unblock with 'mariadb-admin flush-hosts' (Mysql2::Error)
Taking a look into the MySQL logs unveiled
Aug 28 11:25:15 server mariadbd[913]: 2024-08-28 11:25:15 10232 [Warning] Aborted connection 10232 to db: 'unconnected' user: 'unauthenticated' host: '10.0.0.1' (This connection closed normally without authentication)
Without Sentry.init we don't see that problem. DB and User in Log message are unaltered, and do not match up with configured credentials.
And I'm quite confused how something could trigger this, cause the database seems to be initialised and not initialised at the same time. Database-Server-IP is used, but Database-Credentials aren't. I'm also missing a good starting point to debug this further.
I'm not really sure this is a problem related to sentry, or the way sentry integrates itself into rails, but somehow it's triggered by the integration.
Note: IP of DB-Host was altered here, but it should be mentioned that the database doesn't run on localhost
Reproduction Steps
I don't know yet.
Expected Behavior
No error? What ever tries to connect to the database should only after connection is initialised by active record?
Actual Behavior
Something triggers a database connection with no or wrong credentials.
Ruby Version
ruby 3.1.3p185 (2022-11-24 revision 1a6b16756e) [arm64-darwin22]
SDK Version
sentry-ruby (5.19.0)
Integration and Its Version
sentry-rails (5.19.0), rails (6.1.7.8)
Sentry Config
No response
I tried using your config in a Rails 6.1.7 app but couldn't reproduce the issue.
It's expected to have a connection triggered when booting a Rails app and it's also unclear to me how having Sentry.init would make it pick up incorrect configuration.
We'll need more information on this case for further investigation. Can you provide a full backtrace of the error?
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
Does this happen regardless of what is configured within that init block?
Yes.
Alright, please provide us with more info. A stacktrace would be helpful.
Stacktrace of what? The first exception happening is after the database blocks further connections.
closing this as stale, please reopen with more info and repro steps if problem still persists:
- other activerecord gems
- database config