Skip to content

Fix audio & video conference bridge: adding port may not update port counter#4164

Merged
nanangizz merged 4 commits intomasterfrom
async-conf-fix-add
Nov 21, 2024
Merged

Fix audio & video conference bridge: adding port may not update port counter#4164
nanangizz merged 4 commits intomasterfrom
async-conf-fix-add

Conversation

@nanangizz
Copy link
Copy Markdown
Member

This is to fix #3928 (comment).

After investigation, it is caused by invalid port counter (e.g: zero or -1 while there are actually some ports added). Conference bridge uses the port counter to iterates the ports, so when it is invalid, no media flow will happen. Furthermore, such invalid port counter case may happen when a port is removed before the add port operation, including increasing the port counter, is completed. The add port operation can never be completed when no async operation is queued.

This PR fix it by:

  • introducing a new async operation for add port operation,
  • only decrement port counter when port add is completed (i.e: internal port state is_new is false).

sauwming
sauwming previously approved these changes Nov 20, 2024
@sauwming sauwming dismissed their stale review November 20, 2024 06:58

CI test failed

@sauwming
Copy link
Copy Markdown
Member

pjsua-test failed, and it seems genuine, already rerun it twice.

@nanangizz
Copy link
Copy Markdown
Member Author

pjsua-test failed, and it seems genuine, already rerun it twice.

I can't reproduce it here, only tried it on Windows though, also it seems to pass Linux test.

Call stack:

3   libsystem_c.dylib                   0x0000000181304b24 _vsnprintf + 224
4   libsystem_c.dylib                   0x00000001812dd088 __snprintf_chk + 48
5   pjsua-arm-apple-darwin23.6.0        0x00000001002a7220 pj_pool_init_int + 140
6   pjsua-arm-apple-darwin23.6.0        0x00000001002a73e0 pj_pool_create_int + 392
7   pjsua-arm-apple-darwin23.6.0        0x00000001002a7d9c cpool_create_pool + 488
8   pjsua-arm-apple-darwin23.6.0        0x00000001002a6e84 pj_pool_create + 64
9   pjsua-arm-apple-darwin23.6.0        0x000000010016be60 create_conf_port + 84
10  pjsua-arm-apple-darwin23.6.0        0x000000010016bc24 pjmedia_conf_add_port + 632

Here the pj_pool_init_int() code:

if (strchr(name, '%') != NULL) {
pj_ansi_snprintf(pool->obj_name, sizeof(pool->obj_name),
name, pool);

Call stack points to snprintf() and remote URI does have %:

From: <sip:I%20have%20spaces@example.net>;tag=;tag=0.13136883094899887

Maybe it is not related to the new async conf?

@nanangizz
Copy link
Copy Markdown
Member Author

nanangizz commented Nov 20, 2024

Just tried the failing Python test using this branch on MacOS (13.1/Intel), still not reproducible.

@sauwming
Copy link
Copy Markdown
Member

Yes, that's strange, I also tried both tests here on my Mac and they completed successfully.

But it's most certainly because of this PR since this is the only one that failed the CI tests in https://github.com/pjsip/pjproject/actions. I have also repeated the CI tests many times over the night and the failed results are consistent.

@sauwming
Copy link
Copy Markdown
Member

sauwming commented Nov 21, 2024

Your intuition is correct. The '%' causes the issue.
Passing the URI as format specifier doesn't make sense:
snprintf(.., ..., "sip:I%20have%20spaces@example.net", ...)

Although not sure why only in this PR it raises the error.

Perhaps we should change it to strstr(.., "%p")?

Another potential issue is that pjmedia_conf_add_port() never specifies that port_name must be NULL terminated, so we probably shouldn't call pj_pool_create(..., name->ptr)

@nanangizz
Copy link
Copy Markdown
Member Author

Perhaps we should change it to strstr(.., "%p")?

Agree. But it may still have a problem, when the name accidentally has %p, the pool name will not be as expected. Perhaps we should also escape/replace any unintended %, but this needs to be done in the apps.

Another potential issue is that pjmedia_conf_add_port() never specifies that port_name must be NULL terminated, so we probably shouldn't call pj_pool_create(..., name->ptr)

Agree.

@nanangizz nanangizz reopened this Nov 21, 2024
@nanangizz nanangizz merged commit e6eb88e into master Nov 21, 2024
@nanangizz nanangizz deleted the async-conf-fix-add branch November 21, 2024 09:03
BarryYin pushed a commit to BarryYin/pjproject that referenced this pull request Feb 3, 2026
…counter (pjsip#4164)

* Fix audio & video conference bridges, adding port may not update port counter.
* Make sure pool name is NULL terminated, don't use remote URI as conf port name when it contains percent char
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants