Skip to content

Commit

Permalink
http: fix listener decrease online
Browse files Browse the repository at this point in the history
  • Loading branch information
lesismal committed Feb 22, 2024
1 parent 6d052f1 commit 422b237
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion nbhttp/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,17 +580,21 @@ func (engine *Engine) AddConnNonTLSNonBlocking(conn *Conn, tlsConfig *tls.Config
nbc, err := nbio.NBConn(conn.Conn)
if err != nil {
conn.Close()
decrease()
logging.Error("AddConnNonTLSNonBlocking failed: %v", err)
return
}
conn.Conn = nbc
if nbc.Session() != nil {
nbc.Close()
decrease()
logging.Error("AddConnNonTLSNonBlocking failed, invalid session: %v", nbc.Session())
return
}
key, err := conn2Array(nbc)
if err != nil {
nbc.Close()
decrease()
logging.Error("AddConnNonTLSNonBlocking failed: %v", err)
return
}
Expand All @@ -599,6 +603,7 @@ func (engine *Engine) AddConnNonTLSNonBlocking(conn *Conn, tlsConfig *tls.Config
if len(engine.conns) >= engine.MaxLoad {
engine.mux.Unlock()
nbc.Close()
decrease()
logging.Error("AddConnNonTLSNonBlocking failed: overload, already has %v online", engine.MaxLoad)
return
}
Expand All @@ -622,9 +627,9 @@ func (engine *Engine) AddConnNonTLSBlocking(conn *Conn, tlsConfig *tls.Config, d
engine.mux.Lock()
if len(engine.conns) >= engine.MaxLoad {
engine.mux.Unlock()
logging.Error("AddConnNonTLSBlocking failed: overload, already has %v online", engine.MaxLoad)
conn.Close()
decrease()
logging.Error("AddConnNonTLSBlocking failed: overload, already has %v online", engine.MaxLoad)
return
}
switch vt := conn.Conn.(type) {
Expand Down Expand Up @@ -660,18 +665,21 @@ func (engine *Engine) AddConnTLSNonBlocking(conn *Conn, tlsConfig *tls.Config, d
nbc, err := nbio.NBConn(conn.Conn)
if err != nil {
conn.Close()
decrease()
logging.Error("AddConnTLSNonBlocking failed: %v", err)
return
}
conn.Conn = nbc
if nbc.Session() != nil {
nbc.Close()
decrease()
logging.Error("AddConnTLSNonBlocking failed: session should not be nil")
return
}
key, err := conn2Array(nbc)
if err != nil {
nbc.Close()
decrease()
logging.Error("AddConnTLSNonBlocking failed: %v", err)
return
}
Expand All @@ -680,6 +688,7 @@ func (engine *Engine) AddConnTLSNonBlocking(conn *Conn, tlsConfig *tls.Config, d
if len(engine.conns) >= engine.MaxLoad {
engine.mux.Unlock()
nbc.Close()
decrease()
logging.Error("AddConnTLSNonBlocking failed: overload, already has %v online", engine.MaxLoad)
return
}
Expand Down

0 comments on commit 422b237

Please sign in to comment.