mirror of
https://github.com/caddyserver/caddy.git
synced 2026-04-24 01:49:32 -04:00
only clean up connections when stopped
This commit is contained in:
parent
050d137e76
commit
f04b77198e
@ -451,6 +451,7 @@ type tunnelState struct {
|
||||
connections map[io.ReadWriteCloser]openConnection
|
||||
closeTimer *time.Timer
|
||||
closeDelay time.Duration
|
||||
stopped bool
|
||||
mu sync.Mutex
|
||||
logger *zap.Logger
|
||||
}
|
||||
@ -472,7 +473,7 @@ func (ts *tunnelState) registerConnection(conn io.ReadWriteCloser, gracefulClose
|
||||
return func() {
|
||||
ts.mu.Lock()
|
||||
delete(ts.connections, conn)
|
||||
if len(ts.connections) == 0 {
|
||||
if len(ts.connections) == 0 && ts.stopped {
|
||||
unregisterDetachedTunnelStates(ts)
|
||||
if ts.closeTimer != nil {
|
||||
if ts.closeTimer.Stop() {
|
||||
@ -490,6 +491,7 @@ func (ts *tunnelState) closeAttachedConnections() error {
|
||||
var err error
|
||||
ts.mu.Lock()
|
||||
defer ts.mu.Unlock()
|
||||
ts.stopped = true
|
||||
for _, oc := range ts.connections {
|
||||
// detached connections are only closed when the upstream is gone from the config
|
||||
if oc.detached {
|
||||
@ -654,6 +656,9 @@ func (ts *tunnelState) closeConnectionsForUpstream(addr string) error {
|
||||
var err error
|
||||
ts.mu.Lock()
|
||||
defer ts.mu.Unlock()
|
||||
if !ts.stopped {
|
||||
return nil
|
||||
}
|
||||
for _, oc := range ts.connections {
|
||||
if oc.upstream != addr {
|
||||
continue
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user