Skip to content

fix(pjsua): honour --rereg-delay for accounts given on the command line - #21

Open
laconicman wants to merge 2 commits into
masterfrom
fix/pjsua-rereg-delay-ignored
Open

laconicman wants to merge 2 commits into
masterfrom
fix/pjsua-rereg-delay-ignored

Conversation

@laconicman

@laconicman laconicman commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

--rereg-delay has no effect on accounts given on the command line. pjsua_app_config.c parses it into the account's reg_retry_interval, but the "Add accounts" loop in app_init() then sets reg_retry_interval = 300 on every such account, after option parsing. For the same reason write_account_settings() never writes the option back. Accounts added at run time (+a, acc add) start from pjsua_acc_config_default() and were never overridden.

I found this while writing a SIPp scenario for pjsip#5313. pjsua started before SIPp was listening on TCP, so the first REGISTER was refused and the retry came about a minute later, whatever --rereg-delay said. The option is listed in --help and written back by write_account_settings(), so a user has every reason to expect it to work.

The assignment arrived in 1.x r3804 (pjsip#1383, the update of the transport adapter sample), which doesn't mention it. --rereg-delay itself is older (pjsip#1044).

Two commits:

67453e8a — drop reg_retry_interval = 300. The parsed value now reaches pjsua_acc_add(), and the config dump writes it back. The reg_first_retry_interval = 60 next to it is left alone on purpose: no option sets it, so the first retry after a failure still comes after about 60 s, and --rereg-delay governs the retries after that. In my SIPp case that means the first retry is still a minute away, so this does not shorten it; I worked around it by registering at run time with +a.

2dcd7caa — say in --help that --rereg-delay=0 disables retries. That is what 0 means for reg_retry_interval in pjsua-lib, and the option could not produce 0 before. A non-numeric value parses as 0 and so disables retries too, as it would for --reg-use-proxy; I did not add validation.

Testing

pjsua on macOS against a closed TCP port, reading the "Scheduling re-registration retry for acc 1 in N seconds" log lines:

pjsua --null-audio --no-udp --id sip:test@127.0.0.1 --registrar 'sip:127.0.0.1:5999;transport=tcp' --realm '*' --username test --password test --rereg-delay=30
Build --rereg-delay Retries scheduled in (s)
master a67b8e81b 30 68, 308
this PR 30 54, 35
this PR 1 67, 7, 6, 1, 0, 4
this PR 0 none

The first retry is the app's 60 s (randomised by reg_retry_random_interval, 10 s), and the ones after it follow --rereg-delay. For an interval below reg_retry_random_interval, schedule_reregistration() currently draws the delay from 0–10 s, so --rereg-delay=1 and =9 behave alike. That is how the library schedules short intervals today and this PR does not touch it.

With --rereg-delay=30 the dc config dump now includes --rereg-delay 30; on master it has none. make builds without new warnings, and tests/pjsua scripts-run/100_simple.py passes.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

The "Add accounts" loop in app_init() set reg_retry_interval = 300 on
every command-line account. The loop runs after option parsing, so the
value parsed for --rereg-delay was discarded, and
write_account_settings() never wrote the option back because the value
always equalled the default.

The assignment came in with r3804 on the 1.x branch, a change to the
transport adapter sample (pjsip#1383) that does not mention it. The option
is older (pjsip#1044). Accounts added at run time by ui_add_account() and
cmd_add_account() were never overridden.

reg_first_retry_interval = 60, set beside it, is left alone: no option
sets it, so the first retry after a failure still comes after about
60 s, and --rereg-delay governs the retries after that.
With --rereg-delay honoured, a 0 now reaches reg_retry_interval, where
pjsua-lib documents it as disabling auto re-registration. The option
could not produce 0 before, because the app overwrote the value. Say so
in the usage text.
@laconicman
laconicman force-pushed the fix/pjsua-rereg-delay-ignored branch from 53fb23d to 2dcd7ca Compare October 6, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant