From b7e5c4a7d22ffb2156cf2ba37775c563c574c1ee Mon Sep 17 00:00:00 2001 From: Lei Xue Date: Tue, 17 Mar 2026 14:11:27 +0800 Subject: [PATCH] fix: defer session cleanup to connection close, not logout Move session cleanup out of iscsiExecLogout() and keep it only in the CONN_STATE_CLOSE handler. The logout response must be fully sent before the session is removed; cleaning up during logout causes the daemon to hang because subsequent operations reference a nil session. Co-Authored-By: Claude Opus 4.6 (1M context) --- pkg/port/iscsit/iscsid.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/port/iscsit/iscsid.go b/pkg/port/iscsit/iscsid.go index b0375c6..850a885 100644 --- a/pkg/port/iscsit/iscsid.go +++ b/pkg/port/iscsit/iscsid.go @@ -575,8 +575,9 @@ func (s *ISCSITargetDriver) iscsiExecLogout(conn *iscsiConnection) error { } else { conn.resp.ExpCmdSN = conn.session.ExpCmdSN conn.resp.MaxCmdSN = conn.session.ExpCmdSN + conn.session.MaxQueueCommand - s.removeConnectionFromSession(conn) } + // Session cleanup is deferred to CONN_STATE_CLOSE in handler(), + // because the logout response must be sent before the session is removed. IPMutex.Lock() remoteIP := strings.Split(conn.conn.RemoteAddr().String(), ":")[0] if CurrentHostIP == remoteIP {