Search code examples
ruby-on-railscentossidekiqhosts-file

Sidekiq can't connect to database?


I have "mariadb" set to 127.0.0.1 in my /etc/hosts file and sidekiq occasionally throws errors such as:

Mysql2::Error::ConnectionError: Unknown MySQL server host 'mariadb' (16)

The VM is not under significant load or anything like that.

Later edit: seems other gems have trouble resolving hosts too:

WARN -- : Unable to record event with remote Sentry server (Errno::EBUSY - Failed to open TCP connection to XXXX.ingest.sentry.io:443 (Device or resource busy - getaddrinfo)):

Anyone have any idea why that may happen?


Solution

  • I've figured this out a couple weeks ago but wanted to be sure before posting an answer.

    I still can't figure out the mechanic of this issue but it was caused by fail2ban.

    I had it running in a container polling the httpd logs and blocking the tremendous amount of bots scraping my sites.

    Also I increased the max file handlers and inotify handlers.

    fs.file-max = 131070
    fs.inotify.max_user_watches = 65536
    

    As soon as I got rid of fail2ban and increased the inotify handlers the errors disappeared.

    Obviously fail2ban gets on the "do not touch" list because of this, and we've rolled out a 404/403/500 handler on application layer that pushes unknown IPs to Cloudflare.

    Although this is probably an edge case I'm leaving this here in hope it helps someone at some point.