Verify socket open when handling err messages
Summary: When a socket is configured to read from `MSG_ERRQUEUE`, the corresponding callback handler for `errMessageCallback_->errMessage(*cmsg)` may close the socket when processing a message. If this happens, `fd_` will be set to -1 (reinitialized) and subsequent calls to `netops::recvmsg(fd_, &msg, MSG_ERRQUEUE)` will fail. On the read failure, an error will be propagated via `failErrMessageRead(__func__, ex)`. This quickly becomes confusing -- you end up with an error message `::recvmsg exited with code 9` (EBADF) with little context. This diff adds logic to check if the socket is still open before each call to `netops::recvmsg(fd_, &msg, MSG_ERRQUEUE)`. If not, we exit out. It's arguable that the application is at fault in this scenario instead of the library. However, I've found this problem and given the complexity, it seems like a scenario worth guarding against in the library. Reviewed By: yfeldblum Differential Revision: D14354115 fbshipit-source-id: 49e1efbbf6cecbe3bf6db7ee6bdfcac4c8aaa8c2
Showing
Please register or sign in to comment