Skip to content

Commit c47e899

Browse files
committed
Finally got around to adressing review comments
1 parent 3bcbc8c commit c47e899

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

pkg/sip/inbound.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (s *Server) cleanupInvites() {
148148
s.imu.Lock()
149149
for it := s.inviteTimeoutQueue.IterateRemoveAfter(inviteCredentialValidity); it.Next(); {
150150
key := it.Item().Value
151-
delete(s.inProgressInvites, *key)
151+
delete(s.inProgressInvites, key)
152152
}
153153
s.imu.Unlock()
154154
}
@@ -161,16 +161,22 @@ func (s *Server) getInvite(sipCallID, toTag, fromTag string) *inProgressInvite {
161161
toTag: toTag,
162162
fromTag: fromTag,
163163
}
164+
164165
s.imu.Lock()
165-
defer s.imu.Unlock()
166-
is, ok := s.inProgressInvites[key]
167-
if ok {
168-
return is
166+
is, exists := s.inProgressInvites[key]
167+
s.imu.Unlock()
168+
if !exists {
169+
s.imu.Lock()
170+
is, exists = s.inProgressInvites[key]
171+
if !exists {
172+
is = &inProgressInvite{sipCallID: sipCallID, timeoutLink: utils.TimeoutQueueItem[dialogKey]{Value: key}}
173+
s.inProgressInvites[key] = is
174+
}
175+
s.imu.Unlock()
169176
}
170-
is = &inProgressInvite{sipCallID: sipCallID}
171-
s.inProgressInvites[key] = is
172-
s.inviteTimeoutQueue.Reset(&utils.TimeoutQueueItem[*dialogKey]{Value: &key})
173177

178+
// Always reset the timeout link, whether just created or not
179+
s.inviteTimeoutQueue.Reset(&is.timeoutLink)
174180
return is
175181
}
176182

pkg/sip/server.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"net"
2525
"net/netip"
2626
"sync"
27-
"sync/atomic"
2827
"time"
2928

3029
"github.com/frostbyte73/core"
@@ -135,19 +134,18 @@ type dialogKey struct {
135134
}
136135

137136
type Server struct {
138-
log logger.Logger
139-
mon *stats.Monitor
140-
region string
141-
sipSrv *sipgo.Server
142-
getIOClient GetIOInfoClient
143-
getRoom GetRoomFunc
144-
sipListeners []io.Closer
145-
sipUnhandled RequestHandler
146-
147-
imu sync.Mutex
148-
inProgressInvites map[dialogKey]*inProgressInvite
149-
inviteTimeoutQueue utils.TimeoutQueue[*dialogKey]
150-
isCleanupTaskRunning atomic.Bool
137+
log logger.Logger
138+
mon *stats.Monitor
139+
region string
140+
sipSrv *sipgo.Server
141+
getIOClient GetIOInfoClient
142+
getRoom GetRoomFunc
143+
sipListeners []io.Closer
144+
sipUnhandled RequestHandler
145+
inviteTimeoutQueue utils.TimeoutQueue[dialogKey]
146+
147+
imu sync.Mutex
148+
inProgressInvites map[dialogKey]*inProgressInvite
151149

152150
closing core.Fuse
153151
cmu sync.RWMutex
@@ -168,9 +166,10 @@ type Server struct {
168166
}
169167

170168
type inProgressInvite struct {
171-
sipCallID string
172-
challenge digest.Challenge
173-
lkCallID string // SCL_* LiveKit call ID assigned to this dialog
169+
sipCallID string
170+
challenge digest.Challenge
171+
lkCallID string // SCL_* LiveKit call ID assigned to this dialog
172+
timeoutLink utils.TimeoutQueueItem[dialogKey]
174173
}
175174

176175
type ServerOption func(s *Server)

0 commit comments

Comments
 (0)