Update bridge.go

pull/5110/head
patterniha 2025-09-09 16:11:18 +03:30
parent 48ce6a576d
commit 9cca6b916c
1 changed files with 9 additions and 3 deletions

View File

@ -133,7 +133,7 @@ func NewBridgeWorker(domain string, tag string, d routing.Dispatcher) (*BridgeWo
terminate := func() { terminate := func() {
worker.Close() worker.Close()
} }
w.timer = signal.CancelAfterInactivity(ctx, terminate, 24*time.Hour) // prevent leak w.timer = signal.CancelAfterInactivity(ctx, terminate, 60*time.Second) // prevent leak
return w, nil return w, nil
} }
@ -166,14 +166,20 @@ func (w *BridgeWorker) handleInternalConn(link *transport.Link) {
for { for {
mb, err := reader.ReadMultiBuffer() mb, err := reader.ReadMultiBuffer()
if err != nil { if err != nil {
break if w.Closed() {
w.timer.SetTimeout(0)
} else {
w.timer.SetTimeout(24 * time.Hour)
}
return
} }
w.timer.Update() w.timer.Update()
for _, b := range mb { for _, b := range mb {
var ctl Control var ctl Control
if err := proto.Unmarshal(b.Bytes(), &ctl); err != nil { if err := proto.Unmarshal(b.Bytes(), &ctl); err != nil {
errors.LogInfoInner(context.Background(), err, "failed to parse proto message") errors.LogInfoInner(context.Background(), err, "failed to parse proto message")
break w.timer.SetTimeout(0)
return
} }
if ctl.State != w.state { if ctl.State != w.state {
w.state = ctl.State w.state = ctl.State