<!-- Kamailio Pull Request Template -->
#### Pre-Submission Checklist <!-- Go over all points below, and after creating the PR, tick all the checkboxes that apply --> <!-- All points should be verified, otherwise, read the CONTRIBUTING guidelines from above--> <!-- If you're unsure about any of these, don't hesitate to ask on sr-dev mailing list --> - [x] Commit message has the format required by CONTRIBUTING guide - [x] Commits are split per component (core, individual modules, libs, utils, ...) - [x] Each component has a single commit (if not, squash them into one commit) - [x] No commits to README files for modules (changes must be done to docbook files in `doc/` subfolder, the README file is autogenerated)
#### Type Of Change - [x] Small bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds new functionality) - [ ] Breaking change (fix or feature that would change existing functionality)
#### Checklist: - [ ] PR should be backported to stable branches - [x] Tested changes locally - [x] Related to issue #3218
#### Description
Per the DB issue in #3218:
I've determined the commit where dialog with db_mode SHUTDOWN stopped working is 1ff86ffceede46c7a67fec92c8319c34c916a545.
This is the change where `PROC_POSTCHILDINIT` was enabled/used.
In dialog.c `child_init()`, there is code that resets the DB mode to NONE if not running in the main process:
```c /* in DB_MODE_SHUTDOWN only PROC_MAIN will do a DB dump at the end, so * for the rest of the processes will be the same as DB_MODE_NONE */ if (dlg_db_mode==DB_MODE_SHUTDOWN && rank!=PROC_MAIN) dlg_db_mode = DB_MODE_NONE; ```
However, because PROC_POSTCHILDINIT has now been enabled for the module, this code effectively disables DB persistence as PROC_POSTCHILDINIT is called in the main process after PROC_MAIN.
I have modified the rank check to `rank!=PROC_POSTCHILDINIT` and can confirm that DB persistence in SHUTDOWN mode is working once again.
Note that the PR changes the logic to:
```c if (dlg_db_mode==DB_MODE_SHUTDOWN && rank!=PROC_POSTCHILDINIT) dlg_db_mode = DB_MODE_NONE; ```
Technically dlg_db_mode will be reset to DB_MODE_NONE when called with rank PROC_MAIN, but the value will be restored when PROC_POSTCHILDINIT is called. I assume this behavior is OK, but otherwise I can change it to:
```c if (dlg_db_mode==DB_MODE_SHUTDOWN && rank!=PROC_MAIN && rank!=PROC_POSTCHILDINIT) dlg_db_mode = DB_MODE_NONE; ``` You can view, comment on, or merge this pull request online at:
https://github.com/kamailio/kamailio/pull/3221
-- Commit Summary --
* dialog: dont reset dlg_db_mode in POSTCHILDINIT for DB_MODE_SHUTDOWN
-- File Changes --
M src/modules/dialog/dialog.c (2)
-- Patch Links --
https://github.com/kamailio/kamailio/pull/3221.patch https://github.com/kamailio/kamailio/pull/3221.diff
Thanks for the PR. This commit was done as part of several changes related to the POSTCHILDINIT topic. Maybe @miconda can have a look, having done the original change to make sure we do not introduce other side-effects.
@shaneqld: thanks for tracking it and troubleshooting details!
If `dlg_db_mode = DB_MODE_NONE` is done on `PROC_MAIN`, then on `PROC_POSTCHILDINIT` is not restored, I don't see how that could happen. Therefore it should better be:
``` if (dlg_db_mode==DB_MODE_SHUTDOWN && rank!=PROC_MAIN && rank!=PROC_POSTCHILDINIT) dlg_db_mode = DB_MODE_NONE; ```
Hi @miconda
If dlg_db_mode = DB_MODE_NONE is done on PROC_MAIN, then on PROC_POSTCHILDINIT is not restored, I don't see how that could happen.
It's restored as the value is reset at the start of `child_init()` as so:
```c static int child_init(int rank) { dlg_db_mode = dlg_db_mode_param; ```
Happy to update the PR if checking against both `PROC_MAIN` and `PROC_POSTCHILDINIT` is preferred.
Indeed, I didn't spot that line, thinking that `dlg_db_mode` is the modparam variable.
Merged #3221 into master.