p2p: return increased timeout

This commit is contained in:
Matus Kysel 2024-01-26 09:29:43 +01:00
parent d49da4348c
commit f0d9f61bf6
No known key found for this signature in database
GPG Key ID: A2A6AB68CB1C0A94
2 changed files with 14 additions and 3 deletions

@ -445,7 +445,18 @@ func (srv *Server) Stop() {
}
close(srv.quit)
srv.lock.Unlock()
stopChan := make(chan struct{})
go func() {
srv.loopWG.Wait()
close(stopChan)
}()
select {
case <-stopChan:
case <-time.After(defaultDialTimeout): // we should use defaultDialTimeout as we can dial just before the shutdown
srv.log.Warn("stop p2p server timeout, forcing stop")
}
}
// sharedUDPConn implements a shared connection. Write sends messages to the underlying connection while read returns

@ -223,8 +223,8 @@ func TestServerStopTimeout(t *testing.T) {
select {
case <-stopChan:
case <-time.After(10 * time.Second):
t.Error("server should be shutdown in 10 seconds")
case <-time.After(defaultDialTimeout + 1*time.Second):
t.Error("server should be shutdown in defaultDialTimeout + 1 seconds")
}
}