Only await POLLOUT events until connected
Non-blocking socket connect(2) involves waiting for the socket to become writeable to detect that a connection has been made. POLLIN events should not be requested until the socket is connected because they are processed even if the iSCSI context is not yet connected. For example, the QEMU iscsi block driver does something like this: iscsi_full_connect_async(...) /* Now wait until the socket becomes ready */ poll(POLLIN|POLLOUT) = POLLIN|POLLOUT /* QEMU calls POLLIN and POLLOUT handlers individually and it happens to * call the POLLIN handler *before* the POLLOUT handler. */ iscsi_service(POLLIN) iscsi_service(POLLOUT) POLLIN processing will read from the socket and consume the error code if connect failed. As a result, the POLLOUT handler will write to a disconnected socket and raise a SIGPIPE which kills the process. Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
This commit is contained in:
@@ -165,11 +165,7 @@ iscsi_get_fd(struct iscsi_context *iscsi)
|
||||
int
|
||||
iscsi_which_events(struct iscsi_context *iscsi)
|
||||
{
|
||||
int events = POLLIN;
|
||||
|
||||
if (iscsi->is_connected == 0) {
|
||||
events |= POLLOUT;
|
||||
}
|
||||
int events = iscsi->is_connected ? POLLIN : POLLOUT;
|
||||
|
||||
if (iscsi->outqueue) {
|
||||
events |= POLLOUT;
|
||||
|
||||
Reference in New Issue
Block a user