Skip to content

Commit

Permalink
fix: infinite loop if port binding fails for all ports for some reason (
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine authored Oct 3, 2024
1 parent 71076a6 commit 91d1822
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/bind/bind_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ func NewBindAllocator(url *url.URL) (*BindAllocator, error) {
func (b *BindAllocator) NextPort() int {
var l *net.TCPListener
var err error

maxTries := 5000

tries := 0
for {
tries++
port := int(b.port.Add(1))
l, err = net.ListenTCP("tcp", &net.TCPAddr{IP: net.ParseIP(b.baseURL.Hostname()), Port: port})

if err != nil {
if tries >= maxTries {
panic("failed to find an open port: " + err.Error())
}
continue
}
_ = l.Close()
Expand Down

0 comments on commit 91d1822

Please sign in to comment.