From 92a468bf74f243c94f2c2a94db96247c962bef03 Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Mon, 1 Jun 2020 18:14:53 +0200 Subject: [PATCH] Fix packets.go:36: unexpected EOF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mysql has a setting called wait_timeout, which defines the duration after which a connection may not be used anymore. Gotify doesn't apply this, and expects the connection to work without timeout. The fix is to set SetConnMaxLifetime, this however, isn't the exact counterpart for wait_timeout on mysql. wait_timeout is relative to the last use of the connection. The go setting uses the creation of the connection as base. Example error output: ``` [mysql] 2020/05/31 17:53:02 packets.go:36: unexpected EOF [GIN] 2020/05/31 - 17:53:02 | 500 | 247.062µs | 10.2.2.1 | GET "/application" Error #01: an error occured while authenticating user (/proj/database/client.go:24) [2020-05-31 17:53:02] invalid connection ``` --- database/database.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/database/database.go b/database/database.go index 676c2521..378472d0 100644 --- a/database/database.go +++ b/database/database.go @@ -3,6 +3,7 @@ package database import ( "os" "path/filepath" + "time" "github.com/gotify/server/v2/auth/password" "github.com/gotify/server/v2/model" @@ -35,6 +36,14 @@ func New(dialect, connection, defaultUser, defaultPass string, strength int, cre db.DB().SetMaxOpenConns(1) } + if dialect == "mysql" { + // Mysql has a setting called wait_timeout, which defines the duration + // after which a connection may not be used anymore. + // The default for this setting on mariadb is 10 minutes. + // See https://github.com/docker-library/mariadb/issues/113 + db.DB().SetConnMaxLifetime(9 * time.Minute) + } + if err := db.AutoMigrate(new(model.User), new(model.Application), new(model.Message), new(model.Client), new(model.PluginConf)).Error; err != nil { return nil, err }