Skip to content

Commit

Permalink
fix (oidc/examples/cli): return free port err properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jimlambrt committed Aug 12, 2024
1 parent b85f9a7 commit ff8e5a3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions oidc/examples/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func main() {
}
oidcPort := os.Getenv("OIDC_PORT")
if oidcPort == "" {
oidcPort, err = func() (string, error) {
oidcPort, err = func() (port string, retErr error) {
addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
if err != nil {
return "", err
Expand All @@ -121,13 +121,23 @@ func main() {
if err != nil {
return "", err
}
defer l.Close()
return strconv.Itoa(l.Addr().(*net.TCPAddr).Port), nil
defer func() {
if l != nil {
if err := l.Close(); err != nil {
retErr = err
}
}
}()
tcpAddr, ok := l.Addr().(*net.TCPAddr)
if !ok {
return "", fmt.Errorf("not a net.TCPAddr")
}
return strconv.Itoa(tcpAddr.Port), nil
}()
if err != nil {
fmt.Fprintf(os.Stderr, "env OIDC_PORT is empty and error finding a free port: %s", err.Error())
return
}
return
}

id, secret := "test-rp", "fido"
Expand Down

0 comments on commit ff8e5a3

Please sign in to comment.