Handle errors from Close() in CheckUDPBufferSize

Added error handling for the Close() method calls in the CheckUDPBufferSize function to satisfy linting rules and improve error logging.
This commit is contained in:
Phi 2023-10-30 09:59:59 +00:00
parent a6ae497c02
commit 7b473f60ae

View File

@ -48,7 +48,11 @@ func CheckUDPBufferSize(wanted int) func(al *alerting.Alerting) {
})
return
}
defer conn.Close()
defer func() {
if err := conn.Close(); err != nil {
log.Warnf("Failed to close connection: %s", err)
}
}()
udpConn, ok := conn.(*net.UDPConn)
if !ok {
@ -68,7 +72,11 @@ func CheckUDPBufferSize(wanted int) func(al *alerting.Alerting) {
})
return
}
defer file.Close()
defer func() {
if err := file.Close(); err != nil {
log.Warnf("Failed to close file: %s", err)
}
}()
size, err := syscall.GetsockoptInt(int(file.Fd()), syscall.SOL_SOCKET, syscall.SO_RCVBUF)
if err != nil {