Skip to content

Commit be7c0f4

Browse files
committed
fix: allow BYE for early dialogs
1 parent c9ec926 commit be7c0f4

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

dialog_client.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,10 @@ func (s *DialogClientSession) WriteBye(ctx context.Context, bye *sip.Request) er
434434
return nil
435435
}
436436

437-
// In case dialog was not updated
438-
if sip.DialogState(state) != sip.DialogStateConfirmed {
439-
return fmt.Errorf("Dialog not confirmed. ACK not send?")
437+
// The caller's UA MAY send a BYE for either
438+
// confirmed or early dialog
439+
if sip.DialogState(state) != sip.DialogStateConfirmed && !s.isEarlyDialog() {
440+
return fmt.Errorf("Dialog not confirmed or did not receive yet any response")
440441
}
441442

442443
tx, err := s.TransactionRequest(ctx, bye)
@@ -461,6 +462,10 @@ func (s *DialogClientSession) WriteBye(ctx context.Context, bye *sip.Request) er
461462
}
462463
}
463464

465+
func (s *DialogClientSession) isEarlyDialog() bool {
466+
return s.InviteResponse != nil && s.InviteResponse.IsProvisional()
467+
}
468+
464469
// newAckRequestUAC creates ACK request for 2xx INVITE
465470
// https://tools.ietf.org/html/rfc3261#section-13.2.2.4
466471
// NOTE: it does not copy Via header. This is left to transport or caller to enforce

dialog_server.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,10 @@ func (s *DialogServerSession) WriteBye(ctx context.Context, bye *sip.Request) er
374374
return nil
375375
}
376376

377+
// https://datatracker.ietf.org/doc/html/rfc3261#section-15
378+
// However, the callee's UA MUST NOT send a BYE on a confirmed dialog
379+
// until it has received an ACK for its 2xx response or until the server
380+
// transaction times out.
377381
if sip.DialogState(state) != sip.DialogStateConfirmed {
378382
return nil
379383
}
@@ -386,11 +390,6 @@ func (s *DialogServerSession) WriteBye(ctx context.Context, bye *sip.Request) er
386390

387391
// This is tricky
388392
defer s.inviteTx.Terminate() // Terminates INVITE in all cases
389-
390-
// https://datatracker.ietf.org/doc/html/rfc3261#section-15
391-
// However, the callee's UA MUST NOT send a BYE on a confirmed dialog
392-
// until it has received an ACK for its 2xx response or until the server
393-
// transaction times out.
394393
for {
395394
state = s.state.Load()
396395
if sip.DialogState(state) < sip.DialogStateConfirmed {

0 commit comments

Comments
 (0)