Skip to content

Commit

Permalink
close listener!
Browse files Browse the repository at this point in the history
  • Loading branch information
linyows committed Oct 4, 2023
1 parent cc82f25 commit 3849880
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions port_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func (p *PortRange) TakeOut() (int, error) {
}

func isPortAvailable(port int) bool {
_, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
return err == nil
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
return false
}
defer ln.Close()
return true
}

0 comments on commit 3849880

Please sign in to comment.