Browse Source

Merge pull request #1632 from slingamn/mysql_safety

fix #1622
tags/v2.7.0-rc1
Shivaram Lingamneni 3 years ago
parent
commit
317720bfc8
No account linked to committer's email address
5 changed files with 23 additions and 0 deletions
  1. 3
    0
      default.yaml
  2. 7
    0
      irc/config.go
  3. 2
    0
      irc/mysql/config.go
  4. 8
    0
      irc/mysql/history.go
  5. 3
    0
      traditional.yaml

+ 3
- 0
default.yaml View File

748
         password: "hunter2"
748
         password: "hunter2"
749
         history-database: "oragono_history"
749
         history-database: "oragono_history"
750
         timeout: 3s
750
         timeout: 3s
751
+        max-conns: 4
752
+        # this may be necessary to prevent middleware from closing your connections:
753
+        #conn-max-lifetime: 180s
751
 
754
 
752
 # languages config
755
 # languages config
753
 languages:
756
 languages:

+ 7
- 0
irc/config.go View File

18
 	"path/filepath"
18
 	"path/filepath"
19
 	"reflect"
19
 	"reflect"
20
 	"regexp"
20
 	"regexp"
21
+	"runtime"
21
 	"strconv"
22
 	"strconv"
22
 	"strings"
23
 	"strings"
23
 	"time"
24
 	"time"
1481
 
1482
 
1482
 	config.Datastore.MySQL.ExpireTime = time.Duration(config.History.Restrictions.ExpireTime)
1483
 	config.Datastore.MySQL.ExpireTime = time.Duration(config.History.Restrictions.ExpireTime)
1483
 	config.Datastore.MySQL.TrackAccountMessages = config.History.Retention.EnableAccountIndexing
1484
 	config.Datastore.MySQL.TrackAccountMessages = config.History.Retention.EnableAccountIndexing
1485
+	if config.Datastore.MySQL.MaxConns == 0 {
1486
+		// #1622: not putting an upper limit on the number of MySQL connections is
1487
+		// potentially dangerous. as a naive heuristic, assume they're running on the
1488
+		// same machine:
1489
+		config.Datastore.MySQL.MaxConns = runtime.NumCPU()
1490
+	}
1484
 
1491
 
1485
 	config.Server.Cloaks.Initialize()
1492
 	config.Server.Cloaks.Initialize()
1486
 	if config.Server.Cloaks.Enabled {
1493
 	if config.Server.Cloaks.Enabled {

+ 2
- 0
irc/mysql/config.go View File

17
 	Password        string
17
 	Password        string
18
 	HistoryDatabase string `yaml:"history-database"`
18
 	HistoryDatabase string `yaml:"history-database"`
19
 	Timeout         time.Duration
19
 	Timeout         time.Duration
20
+	MaxConns        int           `yaml:"max-conns"`
21
+	ConnMaxLifetime time.Duration `yaml:"conn-max-lifetime"`
20
 
22
 
21
 	// XXX these are copied from elsewhere in the config:
23
 	// XXX these are copied from elsewhere in the config:
22
 	ExpireTime           time.Duration
24
 	ExpireTime           time.Duration

+ 8
- 0
irc/mysql/history.go View File

100
 		return err
100
 		return err
101
 	}
101
 	}
102
 
102
 
103
+	if m.config.MaxConns != 0 {
104
+		m.db.SetMaxOpenConns(m.config.MaxConns)
105
+		m.db.SetMaxIdleConns(m.config.MaxConns)
106
+	}
107
+	if m.config.ConnMaxLifetime != 0 {
108
+		m.db.SetConnMaxLifetime(m.config.ConnMaxLifetime)
109
+	}
110
+
103
 	err = m.fixSchemas()
111
 	err = m.fixSchemas()
104
 	if err != nil {
112
 	if err != nil {
105
 		return err
113
 		return err

+ 3
- 0
traditional.yaml View File

721
         password: "hunter2"
721
         password: "hunter2"
722
         history-database: "oragono_history"
722
         history-database: "oragono_history"
723
         timeout: 3s
723
         timeout: 3s
724
+        max-conns: 4
725
+        # this may be necessary to prevent middleware from closing your connections:
726
+        #conn-max-lifetime: 180s
724
 
727
 
725
 # languages config
728
 # languages config
726
 languages:
729
 languages:

Loading…
Cancel
Save