From 7f75a355152d19cb16da997b3342c3198882a6b1 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Thu, 10 Feb 2022 11:16:57 -0500 Subject: [PATCH] bugfix: race condition on hangup could cause us to send dup webhook --- lib/session/call-session.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 4bf151f9..5d087f72 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -48,6 +48,7 @@ class CallSession extends Emitter { this.taskIdx = 0; this.stackIdx = 0; this.callGone = false; + this.notifiedComplete = false; this.tmpFiles = new Set(); @@ -988,6 +989,12 @@ class CallSession extends Emitter { _notifyCallStatusChange({callStatus, sipStatus, duration}) { if (this.callMoved) return; + /* race condition: we hang up at the same time as the caller */ + if (callStatus === CallStatus.Completed) { + if (this.notifiedComplete) return; + this.notifiedComplete = true; + } + assert((typeof duration === 'number' && callStatus === CallStatus.Completed) || (!duration && callStatus !== CallStatus.Completed), 'duration MUST be supplied when call completed AND ONLY when call completed');