Skip to content

Commit

Permalink
use syscall.EADDRINUSE to check if port is in use
Browse files Browse the repository at this point in the history
  • Loading branch information
alexballas committed Dec 30, 2023
1 parent 13c21e7 commit 19cfc57
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion soapcalls/utils/iptools.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package utils

import (
"errors"
"fmt"
"net"
"net/url"
"strconv"
"strings"
"syscall"
"time"
)

Expand Down Expand Up @@ -49,7 +51,7 @@ CHECK:
numberOfchecks++
conn, err := net.Listen("tcp", net.JoinHostPort(ip, strconv.Itoa(port)))
if err != nil {
if strings.Contains(err.Error(), "address already in use") {
if errors.Is(err, syscall.EADDRINUSE) {
if numberOfchecks == 1000 {
return "", fmt.Errorf("port pick error. Checked 1000 ports: %w", err)
}
Expand Down

0 comments on commit 19cfc57

Please sign in to comment.