Skip to content

Commit 92a468b

Browse files
committed
Fix packets.go:36: unexpected EOF
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 #1: an error occured while authenticating user (/proj/database/client.go:24) [2020-05-31 17:53:02] invalid connection ```
1 parent 52efbbc commit 92a468b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

database/database.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package database
33
import (
44
"os"
55
"path/filepath"
6+
"time"
67

78
"github.com/gotify/server/v2/auth/password"
89
"github.com/gotify/server/v2/model"
@@ -35,6 +36,14 @@ func New(dialect, connection, defaultUser, defaultPass string, strength int, cre
3536
db.DB().SetMaxOpenConns(1)
3637
}
3738

39+
if dialect == "mysql" {
40+
// Mysql has a setting called wait_timeout, which defines the duration
41+
// after which a connection may not be used anymore.
42+
// The default for this setting on mariadb is 10 minutes.
43+
// See https://github.com/docker-library/mariadb/issues/113
44+
db.DB().SetConnMaxLifetime(9 * time.Minute)
45+
}
46+
3847
if err := db.AutoMigrate(new(model.User), new(model.Application), new(model.Message), new(model.Client), new(model.PluginConf)).Error; err != nil {
3948
return nil, err
4049
}

0 commit comments

Comments
 (0)