Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialogs loaded from the DB are no longer saved. #3669

Closed
Den4t opened this issue Dec 9, 2023 · 8 comments
Closed

Dialogs loaded from the DB are no longer saved. #3669

Den4t opened this issue Dec 9, 2023 · 8 comments

Comments

@Den4t
Copy link
Contributor

Den4t commented Dec 9, 2023

Hi !

Description

I have а scenario where dialogs are saved at kamailio shutdown and loaded at startup, the dialog module related configuration:

modparam("dialog", "db_url", DBURL)
modparam("dialog", "db_mode", 3)

When kamailio shut down first time all dialogs a saved in DB, upon startup they loaded as expected, but when in some resonable short time kamailio shutdowned again with active dialogs loaded at startup, they not saved in DB.

I think this happens because the dialog dflags in load_dialog_info_from_db function set to zero after dialog loaded, so
in update_dialog_dbinfo_unsafe such dialogs are ignored (no DLG_FLAG_NEW, no DLG_FLAG_CHANGED set).

Debugging Data

Before shutdown:
kamcmd> dlg.list
{
h_entry: 521
h_id: 11463
ref: 2
call-id: 7z32YR9BCg
from_uri: sip:XXXXX@[XXXX:XXXX:b081:1320::1:2c]
to_uri: sip:YYYYY@[XXXX:XXXX:0:201d::a1]
state: 4
start_ts: 1702137597
init_ts: 1702137595
end_ts: 0
duration: 18
timeout: 1702144797
lifetime: 7200
dflags: 643
sflags: 0
iflags: 0
.....

After startup:
kamcmd> dlg.list
{
h_entry: 521
h_id: 11463
ref: 2
call-id: 7z32YR9BCg
from_uri: sip:XXXXX@[XXXX:XXXX:b081:1320::1:2c]
to_uri: sip:YYYYY@[XXXX:XXXX:0:201d::a1]
state: 4
start_ts: 1702137597
init_ts: 1702137636
end_ts: 0
duration: 46
timeout: 1702144798
lifetime: 7201
dflags: 0
sflags: 0
iflags: 0
....

Possible Solutions

At first glance, it's easy to set dlg->flags = DLG_FLAG_CHANGED (or may be to DLG_FLAG_NEW|DLG_FLAG_CHANGED) after loading from the database in load_dialog_info_from_db function, but I'm not sure if this could break anything else (e.g. DMQ).

Additional Information

  • Kamailio Version - kamailio 5.7.2 (x86_64/linux)

  • Operating System:

Ubuntu 18.04.6 LTS

@carstenbock
Copy link
Member

The question is, why do you expect them to be saved again into the DB, if the dialogs were not modified? In your scenario the content from loading seems to be the same as what you want to save afterwards.
This does not look like a bug to me....

@Den4t
Copy link
Contributor Author

Den4t commented Dec 11, 2023

Hi !

Yes, you are right, not modified, but as i said above - "when in some resonable short time kamailio shutdowned again with active dialogs loaded at startup", this can happend for example if i whant to modify scenario when do some mistake, or pod in cloud is migrated for some reason (stop in one location snd start in another), all this can happend during long life dialog sessios.

@mtryfoss
Copy link
Member

The shutdown db mode is special. It should save all dialogs regardless of flag. On startup, all db entries are deleted again in the database.

I did not investigate myself, but based on his descriptions dialogs that are created before the first restart is not kept during the second restart since they're no longer marked as "changed" or "new".

@Den4t
Copy link
Contributor Author

Den4t commented Dec 17, 2023

I did not investigate myself, but based on his descriptions dialogs that are created before the first restart is not kept during the second restart since they're no longer marked as "changed" or "new".

Exactly !

@Den4t
Copy link
Contributor Author

Den4t commented Dec 20, 2023

I have fixed dialog saving with folowing change:
Den4t@0ff12a0

Look like work as expected.

I haven't tested DMQ, but having studied the code in detail, i don't think this change will affect it in any way.
So, if the authors have no objections, I will do a PR.

@mtryfoss
Copy link
Member

I suspect that might cause duplicate entry if any other db mode is used, after restore and then something that causes a change to the dialog - or even, not being deleted correctly since the DLG_FLAG_NEW flag is set.

Please have a look at the remove_dialog_from_db() function. This will return on dialog termination if the flag is set, without deleting from database.

You should probably only do this if:
if(dlg_db_mode == DB_MODE_SHUTDOWN) {

But there may be need to set flags differently for other modes.
It's important to test all modes that can be used when doing such a change.

If opening a pull request, please keep in mind clang-formating of the patch. Your commit will fail on this check.

@Den4t
Copy link
Contributor Author

Den4t commented Dec 21, 2023

You should probably only do this if:
if(dlg_db_mode == DB_MODE_SHUTDOWN) {

Yes, i missed it, will test all the db modes.

@Den4t
Copy link
Contributor Author

Den4t commented Dec 21, 2023

I have tested all 3 DB modes with my latest modifications, the results look correct:

=== Test mode 1 ===
modparam("dialog", "db_url", "sqlite:///etc/kamailio/sqlite.db")
modparam("dialog", "db_mode", 1)

# systemctl start kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0

>> make 2 calls

# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 2
        dflags: 1536
        dflags: 1536

# systemctl stop kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 2
ERROR: connect_unix_sock: connect(/var/run/kamailio//kamailio_ctl): No such file or directory [2]

# systemctl start kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 2
        dflags: 0
        dflags: 0

# systemctl restart kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 2
        dflags: 0
        dflags: 0

# systemctl restart kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 2
        dflags: 0
        dflags: 0

>> terminate calls

# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0

=== Mode 1 looks good.


=== Test mode 2 ===
modparam("dialog", "db_url", "sqlite:///etc/kamailio/sqlite.db")
modparam("dialog", "db_mode", 2)
modparam("dialog", "db_update_period", 5)


# systemctl start kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0


>> make 2 calls

# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 1
        dflags: 1538
        dflags: 1667
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 2
        dflags: 1536
        dflags: 1536

# systemctl stop kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 2
ERROR: connect_unix_sock: connect(/var/run/kamailio//kamailio_ctl): No such file or directory [2]

# systemctl start kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 2
        dflags: 0
        dflags: 0

# systemctl restart kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 2
        dflags: 0
        dflags: 0


>> terminate calls

... after 5 seconds

# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0

=== Mode 2 looks good



=== Test mode 3 ===
modparam("dialog", "db_url", "sqlite:///etc/kamailio/sqlite.db")
modparam("dialog", "db_mode", 3)

# systemctl start kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0


>> make 2 calls


# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0
        dflags: 1667
        dflags: 1667

# systemctl stop kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 2
ERROR: connect_unix_sock: connect(/var/run/kamailio//kamailio_ctl): No such file or directory [2]

# systemctl start kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0
        dflags: 1
        dflags: 1

# systemctl restart kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0
        dflags: 1
        dflags: 1

# systemctl stop kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 2
ERROR: connect_unix_sock: connect(/var/run/kamailio//kamailio_ctl): No such file or directory [2]

# systemctl start kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0
        dflags: 1
        dflags: 1

>>terminate calls

# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0

# systemctl stop kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0
ERROR: connect_unix_sock: connect(/var/run/kamailio//kamailio_ctl): No such file or directory [2]

# systemctl start kamailio
# echo 'select "dlgs: "||count(*) from dialog'|sqlite3 sqlite.db ; kamcmd dlg.list|grep dflags
dlgs: 0


=== Mode 3 looks good also.

miconda pushed a commit that referenced this issue Dec 28, 2023
…tartup when using db_mode 3

- The dialogs that loaded at startup are not saved in DB on shutdown, and so not loaded at restart,
  fixes issue #3669
@miconda miconda closed this as completed Dec 28, 2023
miconda pushed a commit that referenced this issue Jan 16, 2024
…tartup when using db_mode 3

- The dialogs that loaded at startup are not saved in DB on shutdown, and so not loaded at restart,
  fixes issue #3669

(cherry picked from commit 2d00ce5)
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

No branches or pull requests

4 participants