Forcefully cleanup old connections

This commit is contained in:
9seconds
2019-11-19 11:49:27 +03:00
parent ed9689d813
commit 44d339d777
2 changed files with 14 additions and 6 deletions
+4 -5
View File
@@ -11,11 +11,7 @@ type connectionList struct {
connections []*connection
}
func (c *connectionList) Get(conn *ProxyConn) (*connection, error) {
if len(c.connections) > 0 {
c.gc()
}
func (c *connectionList) get(conn *ProxyConn) (*connection, error) {
if len(c.connections) > 0 && c.connections[0].Len() < config.C.MultiplexPerConnection {
if err := c.connections[0].Attach(conn); err == nil {
return c.connections[0], nil
@@ -41,6 +37,9 @@ func (c *connectionList) Get(conn *ProxyConn) (*connection, error) {
func (c *connectionList) gc() {
prevLen := len(c.connections)
if prevLen == 0 {
return
}
for i := len(c.connections) - 1; i >= 0; i-- {
lastIndex := len(c.connections) - 1