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

オープン
#4,840 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

@AdzerKI がすでに取り組んでいます。

2026年11月19日 から。

  • #4841 @AdzerKI による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
go, mysql
領域
database

調査の方向性

The issue identifies getEntDriver as the entry point and links the go-sql-driver/mysql guidance on SetConnMaxLifetime; start by locating that function and checking how it configures the MySQL driver. The issue proposes a three-minute connection lifetime. Done means MySQL connections receive that setting and the reported broken-pipe log stops recurring; an open pull request already addresses the issue.

索引モデルが issue の本文から書いたものです。

説明

kind/bug needs/triage

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.

主要言語
Go
スター
15.1k
フォーク
726
平均マージ
4日 23時間
マージ済み PR(30日)
27

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

crowdsecurity/crowdsec のほかの issue

crowdsecurity/crowdsec の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。