fix(udprelay): фатальная ошибка не ждёт барьер прогрева
This commit is contained in:
1 parent
748d5a07ce
commit
03eb41e2fb
2 files changed
+38
-12
No files matched your search
@@ -51,6 +51,7 @@ type Deps struct {
|
||||
ConnectedStreams *atomic.Int32
|
||||
OnTURNServer func(ip net.IP)
|
||||
fatalCh chan error
|
||||
allocPace *allocPacer
|
||||
}
|
||||
|
||||
func (d *Deps) log() logx.Logger {
|
||||
@@ -91,6 +92,7 @@ func Run(ctx context.Context, dtlsDialer *dtlsdial.Dialer, auth AuthHandler, log
|
||||
ConnectedStreams: connectedStreams,
|
||||
OnTURNServer: onTURNServer,
|
||||
fatalCh: fatalCh,
|
||||
allocPace: newAllocPacer(allocPaceInterval),
|
||||
}
|
||||
|
||||
runCtx, runCancel := context.WithCancel(ctx)
|
||||
@@ -105,6 +107,18 @@ func Run(ctx context.Context, dtlsDialer *dtlsdial.Dialer, auth AuthHandler, log
|
||||
}
|
||||
}()
|
||||
|
||||
var fatalErr atomic.Pointer[error]
|
||||
watcherDone := make(chan struct{})
|
||||
go func() {
|
||||
defer close(watcherDone)
|
||||
select {
|
||||
case err := <-fatalCh:
|
||||
fatalErr.Store(&err)
|
||||
runCancel()
|
||||
case <-runCtx.Done():
|
||||
}
|
||||
}()
|
||||
|
||||
inboundChan := make(chan *Packet, inboundQueueCap)
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Go(deps.guard(func() {
|
||||
@@ -140,18 +154,6 @@ func Run(ctx context.Context, dtlsDialer *dtlsdial.Dialer, auth AuthHandler, log
|
||||
}))
|
||||
}
|
||||
|
||||
var fatalErr atomic.Pointer[error]
|
||||
watcherDone := make(chan struct{})
|
||||
go func() {
|
||||
defer close(watcherDone)
|
||||
select {
|
||||
case err := <-fatalCh:
|
||||
fatalErr.Store(&err)
|
||||
runCancel()
|
||||
case <-runCtx.Done():
|
||||
}
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
runCancel()
|
||||
<-deadlineSet
|
||||
|
||||
Reference in new issue
Block a user