Skip to content

Commit

Permalink
Fix packets.go:36: unexpected EOF
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
jmattheis committed Jun 1, 2020
1 parent 52efbbc commit 92a468b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package database
import (
"os"
"path/filepath"
"time"

"github.com/gotify/server/v2/auth/password"
"github.com/gotify/server/v2/model"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 92a468b

Please sign in to comment.