fix(peer): Add wait group tracking to goroutines for graceful shutdown

This commit is contained in:
zarazaex69
2026-04-09 19:14:06 +03:00
parent 9ad73c7c88
commit cd634ce9b6

View File

@@ -105,7 +105,11 @@ func (p *Peer) Connect(ctx context.Context) error {
dcReady := make(chan struct{})
p.dc.OnOpen(func() {
log.Println("DataChannel opened")
go p.processSendQueue()
p.wg.Add(1)
go func() {
defer p.wg.Done()
p.processSendQueue()
}()
close(dcReady)
})
@@ -156,7 +160,11 @@ func (p *Peer) Connect(ctx context.Context) error {
ws.SetReadDeadline(time.Now().Add(60 * time.Second))
go p.keepAlive()
p.wg.Add(1)
go func() {
defer p.wg.Done()
p.keepAlive()
}()
if err := p.sendHello(); err != nil {
return err