Skip to content

Commit 7060001

Browse files
fix: Time-of-check Time-of-use bug in session management
1 parent af206e6 commit 7060001

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

internal/smf/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (s *SMF) CreateSmContext(ctx context.Context, supi etsi.SUPI, pduSessionID
112112
}
113113
}
114114
smContext.Mutex.Unlock()
115-
s.RemoveSession(ctx, smContext.CanonicalName())
115+
s.removeSessionUnlocked(ctx, smContext.CanonicalName())
116116
}
117117
}()
118118

internal/smf/release.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ func (s *SMF) ReleaseSmContext(ctx context.Context, smContextRef string) error {
2525
)
2626
defer span.End()
2727

28-
smContext := s.GetSession(smContextRef)
28+
s.mu.Lock()
29+
defer s.mu.Unlock()
30+
31+
smContext := s.pool[smContextRef]
2932
if smContext == nil {
3033
span.RecordError(fmt.Errorf("sm context not found"))
3134
span.SetStatus(codes.Error, "sm context not found")
@@ -54,12 +57,12 @@ func (s *SMF) ReleaseSmContext(ctx context.Context, smContextRef string) error {
5457
if err != nil {
5558
span.RecordError(err)
5659
span.SetStatus(codes.Error, "failed to release tunnel")
57-
s.removeSessionUnlocked(ctx, smContextRef)
60+
delete(s.pool, smContextRef)
5861

5962
return fmt.Errorf("release tunnel failed: %v", err)
6063
}
6164

62-
s.removeSessionUnlocked(ctx, smContextRef)
65+
delete(s.pool, smContextRef)
6366

6467
return nil
6568
}

0 commit comments

Comments
 (0)