Fix close race in DatagramSession

This commit is contained in:
eyedeekay
2025-06-01 18:14:24 -04:00
parent 88c2168ee0
commit 7eea63b351
2 changed files with 6 additions and 7 deletions

View File

@ -2,7 +2,6 @@ package raw
import (
"context"
"fmt"
"net"
"time"
@ -97,8 +96,3 @@ func (rs *RawSession) DialI2PContext(ctx context.Context, addr i2pkeys.I2PAddr)
logger.WithField("session_id", rs.ID()).Debug("Successfully created I2P raw connection")
return conn, nil
}
// generateSessionID generates a unique session identifier
func generateSessionID() string {
return fmt.Sprintf("raw_%d", time.Now().UnixNano())
}

View File

@ -39,7 +39,12 @@ func (r *RawReader) Close() error {
return nil
}
logger := log.WithField("session_id", r.session.ID())
// Fix: Safe session ID retrieval with nil checks
sessionID := "unknown"
if r.session != nil && r.session.BaseSession != nil {
sessionID = r.session.ID()
}
logger := log.WithField("session_id", sessionID)
logger.Debug("Closing RawReader")
r.closed = true