refactor: cleanup error checks in Windows#6
Conversation
Also add tests and add copyright section to README
There was a problem hiding this comment.
Code Review
This pull request updates the conncheck library by adding a copyright section to the README, improving error handling in the core logic, and expanding test coverage. Specifically, it adds a nil check for SyscallConn results and refactors the Windows-specific peek logic for better error reporting. Feedback suggests further refining the Windows implementation by explicitly checking for socket-related errors like WSAENOTSOCK or WSAENOTCONN to return a more accurate status when setting socket options fails.
| if sockOptErr != nil { | ||
| // We couldn't set the timeout and do the check. | ||
| // TODO: Determine if the reason is that the socket is closed and return NotOpen in that case | ||
| return StatusUnknown | ||
| } |
There was a problem hiding this comment.
When sockOptErr is non-nil, the function currently returns StatusUnknown. However, if the error indicates that the socket is closed, not connected, or has been shut down (e.g., WSAENOTSOCK, WSAENOTCONN, or WSAESHUTDOWN), we can definitively return StatusNotOpen. This addresses the TODO on line 66 and improves the accuracy of the liveness check on Windows by reducing false positives (where a closed connection might be assumed open).
if sockOptErr != nil {
if errors.Is(sockOptErr, windows.WSAENOTSOCK) ||
errors.Is(sockOptErr, windows.WSAENOTCONN) ||
errors.Is(sockOptErr, windows.WSAESHUTDOWN) {
return StatusNotOpen
}
return StatusUnknown
}
No description provided.