Skip to content

Commit 6dcbed5

Browse files
authored
Merge pull request #306 from se7entyse7en/configurable-conn-max-lifetime
Adds possibility to configure conn max lifetime
2 parents a0826af + d0e8c75 commit 6dcbed5

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Any of the previous execution methods accept configuration through the following
7676
| `GITBASEPG_PORT` | `--port` | `8080` | Port to bind the HTTP server |
7777
| `GITBASEPG_SERVER_URL` | `--server` | | URL used to access the application in the form `HOSTNAME[:PORT]`. Leave it unset to allow connections from any proxy or public address |
7878
| `GITBASEPG_DB_CONNECTION` | `--db` | `root@tcp(localhost:3306)/none?maxAllowedPacket=4194304` | 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). |
79+
| `GITBASEPG_CONN_MAX_LIFETIME` | `--conn-max-lifetime` | `30` | Maximum amount of time a SQL connection may be reused, in seconds. Make sure this value is lower than the timeout configured in the gitbase server, set with [`GITBASE_CONNECTION_TIMEOUT`](https://docs.sourced.tech/gitbase/using-gitbase/configuration#environment-variables) |
7980
| `GITBASEPG_BBLFSH_SERVER_URL` | `--bblfsh` | `127.0.0.1:9432` | Address where bblfsh server is listening |
8081
| `GITBASEPG_SELECT_LIMIT` | `--select-limit` | `100` | Default `LIMIT` forced on all the SQL queries done from the UI. Set it to 0 to remove any limit |
8182
| `GITBASEPG_FOOTER_HTML` | `--footer` | | 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 |

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)