Skip to content

Commit fb11639

Browse files
committed
Added possibility to configure conn max lifetime
Signed-off-by: Lou Marvin Caraig <loumarvincaraig@gmail.com>
1 parent a0826af commit fb11639

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

cmd/gitbase-web/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"net/http"
8+
"time"
89

910
"github.com/sirupsen/logrus"
1011
"github.com/src-d/gitbase-web/server"
@@ -37,6 +38,7 @@ type ServeCommand struct {
3738
Port int `long:"port" env:"GITBASEPG_PORT" default:"8080" description:"Port to bind the HTTP server"`
3839
ServerURL string `long:"server" env:"GITBASEPG_SERVER_URL" description:"URL used to access the application in the form 'HOSTNAME[:PORT]'. Leave it unset to allow connections from any proxy or public address"`
3940
DBConn string `long:"db" env:"GITBASEPG_DB_CONNECTION" default:"root@tcp(localhost:3306)/none?maxAllowedPacket=4194304" description:"gitbase connection string. Use the DSN (Data Source Name) format described in the Go MySQL Driver docs: https://github.com/go-sql-driver/mysql#dsn-data-source-name"`
41+
ConnMaxLifetime int `long:"conn-max-lifetime" env:"GITBASEPG_CONN_MAX_LIFETIME" default:"30" description:"Connections max life time since their creation in seconds"`
4042
SelectLimit int `long:"select-limit" env:"GITBASEPG_SELECT_LIMIT" default:"100" description:"Default 'LIMIT' forced on all the SQL queries done from the UI. Set it to 0 to remove any limit"`
4143
BblfshServerURL string `long:"bblfsh" env:"GITBASEPG_BBLFSH_SERVER_URL" default:"127.0.0.1:9432" description:"Address where bblfsh server is listening"`
4244
FooterHTML string `long:"footer" env:"GITBASEPG_FOOTER_HTML" description:"Allows to add any custom html to the page footer. It must be a string encoded in base64. Use it, for example, to add your analytics tracking code snippet"`
@@ -52,7 +54,7 @@ func (c *ServeCommand) Execute(args []string) error {
5254
}
5355
defer db.Close()
5456

55-
db.SetMaxIdleConns(0)
57+
db.SetConnMaxLifetime(time.Duration(c.ConnMaxLifetime) * time.Second)
5658

5759
static := handler.NewStatic("build/public", c.ServerURL, c.SelectLimit, c.FooterHTML)
5860

0 commit comments

Comments
 (0)