Fix "address already in use" after wwclient --once

- Closes: #2009

Signed-off-by: Jonathon Anderson <janderson@ciq.com>
This commit is contained in:
Jonathon Anderson
2025-09-06 19:08:45 -06:00
parent 4f4a3dcebe
commit a4bde3b279
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 - Renamed debian.interfaces overlay to ifupdown
### Fixed
- Fix "address already in use" in `wwclient` when `secure: true`. #2009
## v4.6.4, 2025-09-05 ## v4.6.4, 2025-09-05
### Added ### Added

View File

@@ -115,6 +115,20 @@ func CobraRunE(cmd *cobra.Command, args []string) (err error) {
LocalAddr: &localTCPAddr, LocalAddr: &localTCPAddr,
Timeout: 30 * time.Second, Timeout: 30 * time.Second,
KeepAlive: 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, }).DialContext,
MaxIdleConns: 100, MaxIdleConns: 100,
IdleConnTimeout: 2 * time.Duration(conf.Warewulf.UpdateInterval) * time.Second, 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) wwlog.Debug("making request: %s", getURL)
resp, err = Webclient.Get(getURL.String()) resp, err = Webclient.Get(getURL.String())
if err == nil { if err == nil {
defer resp.Body.Close()
break break
} else { } else {
if counter > 60 { if counter > 60 {
@@ -510,6 +525,12 @@ func copyFile(src, dst string, srcInfo os.FileInfo) error {
} }
func cleanUp() { 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) err := pidfile.Remove(PIDFile)
if err != nil { if err != nil {
wwlog.Error("could not remove pidfile: %s", err) wwlog.Error("could not remove pidfile: %s", err)