Merge pull request #2010 from anderbubble/2009-wwclient-once-address-already-in-use

Fix "address already in use" from wwclient when secure=true
This commit is contained in:
Christian Goll
2025-10-14 21:11:50 +02:00
committed by GitHub
2 changed files with 25 additions and 0 deletions

View File

@@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Renamed debian.interfaces overlay to ifupdown
### Fixed
- Fix "address already in use" in `wwclient` when `secure: true`. #2009
## v4.6.4, 2025-09-05
### Added

View File

@@ -115,6 +115,20 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
LocalAddr: &localTCPAddr,
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
Control: func(network, address string, c syscall.RawConn) error {
var sockoptErr error
err := c.Control(func(fd uintptr) {
// Set SO_REUSEADDR to allow immediate reuse of the local port
sockoptErr = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
})
if err != nil {
return err
}
if sockoptErr != nil {
return sockoptErr
}
return nil
},
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 2 * time.Duration(conf.Warewulf.UpdateInterval) * time.Second,
@@ -271,6 +285,7 @@ func updateSystem(target string, ipaddr string, port int, wwid string, tag strin
wwlog.Debug("making request: %s", getURL)
resp, err = Webclient.Get(getURL.String())
if err == nil {
defer resp.Body.Close()
break
} else {
if counter > 60 {
@@ -510,6 +525,12 @@ func copyFile(src, dst string, srcInfo os.FileInfo) error {
}
func cleanUp() {
// Close idle connections to prevent "address already in use" errors
if Webclient != nil {
if transport, ok := Webclient.Transport.(*http.Transport); ok {
transport.CloseIdleConnections()
}
}
err := pidfile.Remove(PIDFile)
if err != nil {
wwlog.Error("could not remove pidfile: %s", err)