tsnet: clean up related to 3c1be083a4

Addresses a few comments left after merging
https://github.com/tailscale/tailscale/pull/18376

Updates #cleanup
Signed-off-by: Harry Harpham <harry@tailscale.com>
hwh33/clear-tsnet-serve-config-only-once-followup
Harry Harpham 2 days ago
parent 3c1be083a4
commit 29dc1cceff
No known key found for this signature in database

@ -1468,8 +1468,8 @@ func (a addr) String() string { return a.ln.addr }
// cleanupListener wraps a net.Listener with a function to be run on Close.
type cleanupListener struct {
net.Listener
cleanup func() error
cleanupOnce sync.Once
cleanup func() error // nil if unused
}
func (cl *cleanupListener) Close() error {
@ -1479,15 +1479,5 @@ func (cl *cleanupListener) Close() error {
cleanupErr = cl.cleanup()
}
})
closeErr := cl.Listener.Close()
switch {
case closeErr != nil && cleanupErr != nil:
return fmt.Errorf("%w; also: %w", closeErr, cleanupErr)
case closeErr != nil:
return closeErr
case cleanupErr != nil:
return cleanupErr
default:
return nil
}
return errors.Join(cl.Listener.Close(), cleanupErr)
}

Loading…
Cancel
Save