From 25eb87c7ee8be65cbba9c63a5720e11eddfa27c7 Mon Sep 17 00:00:00 2001 From: Felipe Franciosi Date: Sat, 25 Nov 2017 17:12:38 +0000 Subject: [PATCH] sync: cancel pending pdus on error The set of sync connect calls use a stack variable to track the connection status. This is ok because such calls block on event_poll() until the connection is established. However, event_poll may return early in case of errors (or timeout) while PDUs are still queued on the context (and pointing to a local stack). This cancels any pending PDUs before returning from sync connect calls. Signed-off-by: Felipe Franciosi --- lib/sync.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/sync.c b/lib/sync.c index 5b209d7..f8a139c 100644 --- a/lib/sync.c +++ b/lib/sync.c @@ -114,6 +114,11 @@ iscsi_connect_sync(struct iscsi_context *iscsi, const char *portal) /* clear connect_data so it doesnt point to our stack */ iscsi->connect_data = NULL; + /* in case of error, cancel any pending pdus */ + if (state.status != SCSI_STATUS_GOOD) { + iscsi_cancel_pdus(iscsi); + } + return (state.status == SCSI_STATUS_GOOD) ? 0 : -1; } @@ -135,9 +140,9 @@ iscsi_full_connect_sync(struct iscsi_context *iscsi, event_loop(iscsi, &state); - /* in case of error, clear loggedin flag to prevent pending pdu callbacks */ - if (state.status != 0) { - iscsi->is_loggedin = 0; + /* in case of error, cancel any pending pdus */ + if (state.status != SCSI_STATUS_GOOD) { + iscsi_cancel_pdus(iscsi); } return (state.status == SCSI_STATUS_GOOD) ? 0 : -1;