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 #01: an error occured while authenticating user (/proj/database/client.go:24) [2020-05-31 17:53:02] invalid connection ```
This commit is contained in:
parent
52efbbcceb
commit
92a468bf74
|
|
@ -3,6 +3,7 @@ package database
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gotify/server/v2/auth/password"
|
"github.com/gotify/server/v2/auth/password"
|
||||||
"github.com/gotify/server/v2/model"
|
"github.com/gotify/server/v2/model"
|
||||||
|
|
@ -35,6 +36,14 @@ func New(dialect, connection, defaultUser, defaultPass string, strength int, cre
|
||||||
db.DB().SetMaxOpenConns(1)
|
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 {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue