server: try avoid the "address already in use" error (#8842)
Replace defer l.Close() with l.Close() to shutdown the listener as fast as possible to avoid the "bind: address already in use" error that so often occurs in CI build. From: https://github.com/phayes/freeport/pull/8 Reference: #6671 Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
This commit is contained in:
parent
a4b7f76110
commit
d02a39739b
@ -13,16 +13,10 @@ func FreeTCPAddr() (addr, port string, err error) {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
closer := func() {
|
||||
err := l.Close()
|
||||
if err != nil {
|
||||
// TODO: Handle with #870
|
||||
panic(err)
|
||||
}
|
||||
if err := l.Close(); err != nil {
|
||||
return "", "", fmt.Errorf("couldn't close the listener: %w", err)
|
||||
}
|
||||
|
||||
defer closer()
|
||||
|
||||
portI := l.Addr().(*net.TCPAddr).Port
|
||||
port = fmt.Sprintf("%d", portI)
|
||||
addr = fmt.Sprintf("tcp://0.0.0.0:%s", port)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user