Skip to content

Commit 8051ebe

Browse files
PerondasPerondasPerondascloudwebrtc
authored
Fix bug where stopping the SIPUAHelper caused a ConcurrentModificationError. Closes #282 (#283)
* Added default response to cancellation * Added flag to stop ConcurrentModificationError when stopping ua * update. Co-authored-by: Perondas <114622@fhwn.ac.at> Co-authored-by: Perondas <Pperondas@gmail.com> Co-authored-by: cloudwebrtc <duanweiwei1982@gmail.com>
1 parent 5fc51c1 commit 8051ebe

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/src/transactions/invite_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class InviteClientTransaction extends TransactionBase {
112112
transport!.send(ack);
113113
}
114114

115-
void cancel(String reason) {
115+
void cancel(String? reason) {
116116
// Send only if a provisional response (>100) has been received.
117117
if (state != TransactionState.PROCEEDING) {
118118
return;

lib/src/ua.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ class UA extends EventManager {
154154

155155
TransactionBag get transactions => _transactions;
156156

157+
// Flag that indicates whether UA is currently stopping
158+
bool _stopping = false;
159+
157160
// ============
158161
// High Level API
159162
// ============
@@ -364,6 +367,8 @@ class UA extends EventManager {
364367
}
365368
});
366369

370+
_stopping = true;
371+
367372
// Run _close_ on every applicant.
368373
for (Applicant applicant in _applicants) {
369374
try {
@@ -505,6 +510,9 @@ class UA extends EventManager {
505510
* Message
506511
*/
507512
void newMessage(Message message, String originator, dynamic request) {
513+
if (_stopping) {
514+
return;
515+
}
508516
_applicants.add(message);
509517
emit(EventNewMessage(
510518
message: message, originator: originator, request: request));
@@ -514,7 +522,11 @@ class UA extends EventManager {
514522
* Options
515523
*/
516524
void newOptions(Options message, String originator, dynamic request) {
525+
if (_stopping) {
526+
return;
527+
}
517528
_applicants.add(message);
529+
518530
emit(EventNewOptions(
519531
message: message, originator: originator, request: request));
520532
}
@@ -523,13 +535,19 @@ class UA extends EventManager {
523535
* Message destroyed.
524536
*/
525537
void destroyMessage(Message message) {
538+
if (_stopping) {
539+
return;
540+
}
526541
_applicants.remove(message);
527542
}
528543

529544
/**
530545
* Options destroyed.
531546
*/
532547
void destroyOptions(Options message) {
548+
if (_stopping) {
549+
return;
550+
}
533551
_applicants.remove(message);
534552
}
535553

0 commit comments

Comments
 (0)