Repository navigation
Conversation
|
Hi, @Lt-Flash ! I am curious whether this is this something that you actually hit in production/testing, or it is just a theoretical fix. Because I can totally agree it may happen, but it is very unlikely :). Did you hit it? What do you think? do you want to give it a try using this approach? If not, I can work out something myself to get this fixed. Best regards, |
|
Hi @razvancrainea, Thanks a lot for looking into this so quickly! Yes, I'm afraid it's real, not just theory. Customers noticed it and reported it to support: dead air, calls left up on their PBX, hold and transfer failing mid-call. When I traced those calls, I found the same It's less rare than it looks. A node takes the id on the INVITE, but replicates the dialog only once it's answered. So the window is the whole ringing time. #4397 reproduces it on every run. I needed a quick fix to help the customers, so I opened this PR. I built OpenSIPS with it and put it into production, and it helped. Thank you for catching the mistake in my patch, much appreciated. The create branch returns before the FROM_DB/SYNCED handling. So a colliding local dialog could be dropped at the end of a sync. I didn't hit it because I keep no dialogs in a database and use no sharing tags. I really like your instance id idea. It's a much better fix, and I'd be happy to implement it. A few questions before I start:
Thanks again! |
|
Hi, @Lt-Flash !
Thanks a lot for your report and taking care of this! Cheers, |
|
Hi @razvancrainea, Thanks a lot for your reply! I am glad to help with resolving this issue. One other idea: take the byte from
The code change is small: the allocation, and the three "next_id follows the max" places, which would follow only ids of my own instance. The counter per bucket becomes 24 bits instead of 32, so it wraps after 2^24 dialogs per bucket. The parameter (say The two commits of this PR could stay as a guard, for partly upgraded clusters and for a restarted node until its sync completes. Whether to keep them is up to you: I am happy to implement both, or the instance alone. Is the Thanks again! |
|
One more point for the choice between the two bytes, about the dialog DB. I tested it. The DB Test: the tree of this PR plus a test-only patch that puts an instance byte in either place, MariaDB 11.8.6 with the stock
I ran 128 with So the |
|
Hi, Yuri! That seems to be a different bug - although the table is created as unsigned bigint, the module uses it as a signed - this is not correct (even now) and should be fixed. I'll try to double check who is using bigint signed, and if nobody does, amend the interface to always use bigint as unsigned. I will work on this meanwhile. Best regards, |
|
Hi @razvancrainea, Thanks! I will put the instance in the top byte of Two points before I write the code:
In the dialog itself I plan to keep Thanks again! |
|
Hi, Yuri! Best regards, |
ffe9bd6 to
f7a0b72
Compare
|
Hi @razvancrainea, I have pushed the instance id to this PR, rebased on master.
I kept the two guard commits: as you said, once the ids cannot collide, a collision means a misconfiguration and can be ignored. Thanks! |
f7a0b72 to
e964e8e
Compare
|
I rebased the branch on the current master (9c442ad) to resolve the conflicts. The only conflict was in I also checked the dialog changes that landed since my last push (the lifetime and delete-delay timer wheels, |
Since the replication format matches dialogs by their id, the update, value and delete handlers find their dialog by (h_entry, h_id) only, but the id is unique only on the node that created the dialog. Every node raises its next_id past the ids it receives, and a dialog gets its id at the initial INVITE while it is replicated only once answered. So two nodes creating dialogs in the same hash entry while the first call is still ringing can give both calls the same id, and the packets of one call are then applied to the other: contacts and SDPs overwritten (a topology-hidden BYE was sent to the other call's contact), dialog values replaced, and a live dialog deleted when the other call hung up. Check the Call-ID (and the caller tag, where the packet carries it) of the dialog found by id, and log and drop the packet on a mismatch, as the CSeq handler already does through match_dialog(). The create handler also logs such a collision instead of treating the dialog as already created.
When a replicated create hit a local dialog of another call with the same id, dlg_replicated_create() returned before clearing DLG_FLAG_FROM_DB and setting DLG_FLAG_SYNCED on it, unlike before the collision check was added. During a cluster sync the local dialog then looked absent from the sync data and was dropped at SYNC_DONE: dialogs loaded from the database, and dialogs without a sharing tag, which always count as needing a sync. Only log the collision there and keep the previous flag handling.
Nodes replicating dialogs to each other allocate ids on their own, so two nodes can give the same (h_entry, h_id) to two different calls. The new instance_id parameter (0-127) goes in the top byte of h_entry, so ids made by different instances never match. It defaults to the node id in dialog_replication_cluster; an invalid value stops the startup. h_entry keeps the hash table index in its low 24 bits, and the did, the DB dlg_id and the API carry the whole value. Replication packets go to version 6, which carries the instance after h_id. Version 5 packets are still accepted and read as instance 0, the instance of a node without this change. Upgrading a cluster: nodes without this change drop version 6 packets, as they did with version 5. While a cluster is half upgraded, the old nodes get no dialogs created on the upgraded nodes, and a dialog an old node created stays there until its timeout when it ends through an upgraded node.
e964e8e to
4c4133f
Compare
The instance sits in the top byte of h_entry, so a hash table bigger than 2^24 entries would mix index bits into the instance: refuse such a hash_size whatever the instance is. The database load paths used the stored hash entry as a table index without checking it, so rows saved with a bigger hash_size were read and written out of bounds. Skip such rows with an error.
4c4133f to
1e2bcd0
Compare
|
For the curious, we had also hit this in production at heavy peaks. We made our own temporary work around awaiting this solution. We made it so a shared update is ignored unless its Call-ID matches, not as well integrated as this, but it prevents the collisions. |
Summary
Stop dialog replication from applying one call's update, value and delete packets to a different call that got the same dialog id on another node.
Details
This is a bug fix for any dialog replication cluster where more than one node creates dialogs, such as several active nodes behind an anycast address. Issue #4397 has the full analysis and a reproduction.
Since b3c31fb the replication handlers find their dialog by
(h_entry, h_id)only, which assumes the id is unique in the cluster. It is not: a node allocates the id on the initial INVITE but replicates the dialog only once it is answered, and every node raises itsnext_idpast the ids it receives. So while a call rings on one node, another node can give a new call the same id. From then on:Solution
A new helper,
dlg_repl_id_collision(), compares the Call-ID, and the caller tag when the packet carries one, of the dialog found by id with the packet. On a mismatch it logs(without the From tags for value packets, which do not carry one) and the handler drops the packet. It is called:
dlg_replicated_update()before the "not found, build a new dialog" branch, so no second dialog with the same id is created either;dlg_replicated_value(), on the Call-ID only, as value packets carry no tags;dlg_replicated_delete(), under the entry lock, sincelookup_dlg()returns with the lock released and the legs array can be reallocated; the reference taken bylookup_dlg()is released on a mismatch;dlg_replicated_create(), which keeps skipping the packet but now logs the collision.The check applies only to lookups by id (
DLG_BIN_V4and later; value packets always); older packets are already matched by Call-ID and tags. It does not affect the looping case b3c31fb was written for: looped dialogs share the Call-ID and From tag, so they pass the check and the id still picks the right one.Two nodes can still give the same id to two calls; on the other nodes one of the two calls then has no replica, and an in-dialog request for it that reaches such a node is not matched. This PR does not change id allocation.
How I tested it: two nodes on one host as in #4397, with collisions forced on every run, comparing master 6abfdcc with this branch:
Builds: the whole tree with gcc 14.2.0 and
-Werror(0 warnings), and the dialog module with clang 19.1.7 and-Werror.Compatibility
No configuration, script or replication format change. Packets that belong to the dialog found by id always carry its Call-ID and caller tag, so they are applied as before. The only visible change is the new error line on a collision. There is no platform-specific code.
Closing issues
closes #4397