b2b_logic: fix duplicate out_sdp serialization in entity_storage #3772
+0
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a bug in B2B entity replication (
clusterer+b2b_logic) where theout_sdpfield is pushed twice into the binary packet during packing, but consumed only once during unpacking. The mismatch corrupts the subsequent fields in the packet, includingentity->no, and breaks B2B tuple synchronization across cluster nodes.After this change:
pack_entity()andb2bl_entity_unpack()have matching field sequencesentity->nois correctly restored as0or1Bad entity bridge no [...]errors no longer occur in normal operationopensips-cli -x mi b2b_listreports a consistent view of tuples across all nodes.Details
Environment:
proto=bin) with B2B state replication enabledb2b_logicb2b_entitiesclustererProblem description:
When packing B2B entities for cluster replication in
pack_entity(), theout_sdpfield is currently serialized twice:// Around line 133 - entity_storage.c : pack_entity()
However, in receive_entity_create(), out_sdp is deserialized only once, with the expected sequence being:
Because the pack side writes out_sdp twice but the unpack side reads it only once, the binary stream becomes misaligned and all subsequent fields are read from the wrong offset. In clustered deployments this corrupts the reconstructed entity, including entity->no, which leads to errors such as:
On the “good” node (the one where the tuple was originally created), the B2B state looks correct, for example:
On the receiving nodes (after replication), the same tuple fails to deserialize correctly and receive_entity_create() logs an invalid entity->no (e.g. 21349), with the tuple subsequently missing in b2b_list / b2be_list due to the failed creation.
This behaviour is reproducible with:
Solution
The fix is to remove the duplicate serialization of
out_sdpinpack_entity(), so that the packed fields exactly match the unpacked fields inreceive_entity_create().Testing
b2b_logicwith the fix and deployed to a 3‑node SBC clusterBad entity bridge no [...]errors in logsopensips-cli -x mi b2b_listshows the same tuples on all nodesopensips-cli -x mi b2be_listshows consistent dialog / entity state across the clusterCompatibility
pack_entity()andreceive_entity_create()is restored to a consistent state.Closing issues
Fixes issue: #3707