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) <noreply@anthropic.com>
This commit is contained in:
Lei Xue
2026-03-17 14:11:27 +08:00
parent 70e1955487
commit b7e5c4a7d2

View File

@@ -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 {