Skip to content

Fix transport loop#3773

Merged
nanangizz merged 1 commit intopjsip:masterfrom
wosrediinanatour:fix_transport_loop
Nov 24, 2023
Merged

Fix transport loop#3773
nanangizz merged 1 commit intopjsip:masterfrom
wosrediinanatour:fix_transport_loop

Conversation

@wosrediinanatour
Copy link
Copy Markdown
Contributor

@wosrediinanatour wosrediinanatour commented Nov 7, 2023

Transport "loop" need set the base.grp_lock, as also shown in transport_adapter_sample.c to have destroying of the loop transport working.

Issue #3771

struct transport_loop *loop = (struct transport_loop*) arg;

PJ_LOG(4, (loop->base.name, "Loop transport destroyed"));
pj_pool_release(loop->pool);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to erase this, it will cause leak.

Copy link
Copy Markdown
Contributor Author

@wosrediinanatour wosrediinanatour Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then it the pool is released twice: the second time in

pj_pool_release(pool);

which leads to a crash.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the issue is that, the pool is released when the tp is still in use. If the tp is not used any longer, then it will be safe to release the pool. Tested here without removing the pool release, and there's no crash

Copy link
Copy Markdown
Contributor Author

@wosrediinanatour wosrediinanatour Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that there are two pools...

I have to continue debugging...

Anyway... due to 6dc9b8c I get a crash for a code that worked at least since 2.11.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right - it is working for me too.

Transport "loop" need set the `base.grp_lock`, as also shown in
`transport_adapter_sample.c` to have destroying of the loop transport
working.

Issue pjsip#3771
@nanangizz
Copy link
Copy Markdown
Member

IIRC the group lock of transport loop is not exported to base.grp_lock on purpose, i.e: it does not really have socket/ioqueue key and it destroys synchronously (not like ICE which may destroy async-ly for TURN deallocation). After the stream/transport is destroyed, I assume the app does not send any packets (and as it is a loop tp, it also won't receive any packet, so there should be no race condition between receive & destroy). So if you see a crash, perhaps the problem is somewhere else. Unfortunately the issue and this PR do not seem to describe the problem detail, e.g: race condition causing use-after-free.

@wosrediinanatour
Copy link
Copy Markdown
Contributor Author

@nanangizz: In

status = pj_grp_lock_create(pool, NULL, &grp_lock);
the grp_lock is created, but the pointer grp_lock is nowhere stored in this function.

pj_grp_lock_dec_ref(tp->grp_lock);
tries to accesstp->grp_lock - which was never set.
E.g. the pool address is stored by tp->pool = pool; at .

Copy link
Copy Markdown
Member

@nanangizz nanangizz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wosrediinanatour You're absolutely right! Thanks for pointing it out.

@nanangizz nanangizz merged commit f9ed97b into pjsip:master Nov 24, 2023
@sauwming sauwming linked an issue Nov 28, 2023 that may be closed by this pull request
trengginas pushed a commit that referenced this pull request Mar 11, 2024
Transport "loop" need set the `base.grp_lock`, as also shown in
`transport_adapter_sample.c` to have destroying of the loop transport
working.

Issue #3771
BarryYin pushed a commit to BarryYin/pjproject that referenced this pull request Feb 3, 2026
Transport "loop" need set the `base.grp_lock`, as also shown in
`transport_adapter_sample.c` to have destroying of the loop transport
working.

Issue pjsip#3771
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.

Loop transport does not work with PJSUA(2)

4 participants