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
+10 -1
View File
@@ -2,11 +2,14 @@ package hub
import (
"context"
"time"
"mtg/conntypes"
"mtg/protocol"
)
const muxGCEvery = time.Minute
type muxNewRequest struct {
req *protocol.TelegramRequest
resp chan<- muxNewResponse
@@ -26,6 +29,9 @@ type mux struct {
}
func (m *mux) run() {
gcTicker := time.NewTicker(muxGCEvery)
defer gcTicker.Stop()
for {
select {
case <-m.ctx.Done():
@@ -34,9 +40,12 @@ func (m *mux) run() {
}
return
case <-gcTicker.C:
m.connections.gc()
case req := <-m.channelNew:
m.connections.gc()
proxyConn := newProxyConn(req.req, m.channelClosed)
conn, err := m.connections.Get(proxyConn)
conn, err := m.connections.get(proxyConn)
if err == nil {
m.clients[string(req.req.ConnID[:])] = conn