diff --git a/sippy/ua.go b/sippy/ua.go index 0712880..501fbe1 100644 --- a/sippy/ua.go +++ b/sippy/ua.go @@ -40,12 +40,17 @@ import ( "github.com/sippy/go-b2bua/sippy/utils" ) +type SessionLocker interface { + sync.Locker + TryLock() bool +} + type Ua struct { sip_tm sippy_types.SipTransactionManager sip_tm_lock sync.RWMutex config sippy_conf.Config call_controller sippy_types.CallController - session_lock sync.Locker + session_lock SessionLocker state sippy_types.UaState equeue []sippy_types.CCEvent elast_seq int64 @@ -131,7 +136,7 @@ func (self *Ua) String() string { return "UA state: " + self.state.String() + ", Call-Id: " + self.cId.CallId } -func NewUA(sip_tm sippy_types.SipTransactionManager, config sippy_conf.Config, nh_address *sippy_net.HostPort, call_controller sippy_types.CallController, session_lock sync.Locker, heir sippy_types.UA) *Ua { +func NewUA(sip_tm sippy_types.SipTransactionManager, config sippy_conf.Config, nh_address *sippy_net.HostPort, call_controller sippy_types.CallController, session_lock SessionLocker, heir sippy_types.UA) *Ua { return &Ua{ sip_tm : sip_tm, call_controller : call_controller, @@ -222,9 +227,17 @@ REQ_LOOP: if self.pr_rel { t.SetPrackCBs(self.RecvPRACK, disc_fn) } + cancel_cb := self.state.RecvCancel + cancel_fn := func(rtime *sippy_time.MonoTime, req sippy_types.SipRequest) { + if self.session_lock.TryLock() { + self.session_lock.Unlock() + panic("self.session_lock is not locked") + } + cancel_cb(rtime, req) + } return &sippy_types.Ua_context{ Response : nil, - CancelCB : self.state.RecvCancel, + CancelCB : cancel_fn, NoAckCB : disc_fn, } } else {