crowdsec icon indicating copy to clipboard operation
crowdsec copied to clipboard

MySQL: idle pool connections die after wait_timeout, log shows broken pipe

Open AdzerKI opened this issue 2 weeks ago • 3 comments

With a MySQL backend, crowdsec keeps idle connections in the database/sql pool with no lifetime limit. After the server-side wait_timeout (600s here) MySQL closes them, and the next query on such a connection logs:

[mysql] packets.go:155 write tcp 127.0.0.1:55054->127.0.0.1:3310: write: broken pipe
[mysql] connection.go:803 closing bad idle connection: unexpected read from socket

database/sql retries on a fresh connection, so queries still succeed, but the log gets these lines every time the pool picks a dead connection (about a dozen a day on our host, crowdsec 1.8.2).

go-sql-driver/mysql asks for SetConnMaxLifetime shorter than the server and middleware timeouts and suggests under 5 minutes: https://github.com/go-sql-driver/mysql#important-settings

Fix: set ConnMaxLifetime to 3 minutes for the mysql driver in getEntDriver. PR follows.

AdzerKI avatar Nov 19 '26 22:11 AdzerKI

@AdzerKI: Thanks for opening an issue, it is currently awaiting triage.

In the meantime, you can:

  1. Check Crowdsec Documentation to see if your issue can be self resolved.
  2. You can also join our Discord.
  3. Check Releases to make sure your agent is on the latest version.
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

github-actions[bot] avatar Nov 19 '26 22:11 github-actions[bot]

@AdzerKI: There are no 'kind' label on this issue. You need a 'kind' label to start the triage process.

  • /kind feature
  • /kind enhancement
  • /kind refactoring
  • /kind bug
  • /kind packaging
Details

I am a bot created to help the crowdsecurity developers manage community feedback and contributions. You can check out my manifest file to understand my behavior and what I can do. If you want to use this for your project, you can check out the BirthdayResearch/oss-governance-bot repository.

github-actions[bot] avatar Nov 19 '26 22:11 github-actions[bot]

/kind bug

AdzerKI avatar Nov 20 '26 06:11 AdzerKI