fix: handle discovery sessions in UnBindISCSISession
Discovery sessions have nil Target and nil ITNexus. The cleanup path crashed with nil pointer dereference when trying to remove ITNexus or access Target.Sessions for discovery sessions. Guard against nil Target (just release TSIH) and nil ITNexus. Also add nil safety to clearHostIP helper. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -376,12 +376,19 @@ func (s *ISCSITargetDriver) handler(events byte, conn *iscsiConnection) {
|
||||
}
|
||||
|
||||
func (s *ISCSITargetDriver) clearHostIP(conn *iscsiConnection) {
|
||||
if conn.conn == nil {
|
||||
return
|
||||
}
|
||||
IPMutex.Lock()
|
||||
remoteIP := strings.Split(conn.conn.RemoteAddr().String(), ":")[0]
|
||||
defer IPMutex.Unlock()
|
||||
addr := conn.conn.RemoteAddr()
|
||||
if addr == nil {
|
||||
return
|
||||
}
|
||||
remoteIP := strings.Split(addr.String(), ":")[0]
|
||||
if CurrentHostIP == remoteIP {
|
||||
CurrentHostIP = ""
|
||||
}
|
||||
IPMutex.Unlock()
|
||||
}
|
||||
|
||||
func (s *ISCSITargetDriver) rxHandler(conn *iscsiConnection) {
|
||||
|
||||
@@ -330,10 +330,17 @@ func (s *ISCSITargetDriver) LookupISCSISession(tgtName string, iniName string, i
|
||||
|
||||
func (s *ISCSITargetDriver) UnBindISCSISession(sess *ISCSISession) {
|
||||
target := sess.Target
|
||||
if target == nil {
|
||||
// Discovery sessions have no target; just release the TSIH.
|
||||
s.ReleaseTSIH(sess.TSIH)
|
||||
return
|
||||
}
|
||||
target.SessionsRWMutex.Lock()
|
||||
defer target.SessionsRWMutex.Unlock()
|
||||
delete(target.Sessions, sess.TSIH)
|
||||
scsi.RemoveITNexus(sess.Target.SCSITarget, sess.ITNexus)
|
||||
if sess.ITNexus != nil {
|
||||
scsi.RemoveITNexus(target.SCSITarget, sess.ITNexus)
|
||||
}
|
||||
s.ReleaseTSIH(sess.TSIH)
|
||||
log.Infof("session %x unbound from target %s", sess.TSIH, target.SCSITarget.Name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user