Skip to content

Conversation

albertored
Copy link
Contributor

Diameter message_cb can return an updated callback that should be the one to be called for all subsequent events (recv, send, ack). When returning the new callback in response of a send event the subsequent ack event is notified with the old callback instead of the new one. This happens because the message is sent before parsing all the actions returned by the send callback.

Copy link
Contributor

github-actions bot commented May 8, 2025

CT Test Results

  2 files   34 suites   12m 3s ⏱️
134 tests 129 ✅ 5 💤 0 ❌
162 runs  157 ✅ 5 💤 0 ❌

Results for commit da04f7c.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@albertored albertored changed the title [diameter] Call message_cb 'ack' with updated callback diameter: Call message_cb 'ack' with updated callback May 8, 2025
@jhogberg jhogberg added the team:PS Assigned to OTP team PS label May 12, 2025
@Mikaka27
Copy link
Contributor

Hi, is it possible for you to add a test case that would detect this problem?

@albertored
Copy link
Contributor Author

@Mikaka27 yes, I can try

@Mikaka27 Mikaka27 added the waiting waiting for changes/input from author label Jun 3, 2025
@Mikaka27 Mikaka27 added the testing currently being tested, tag is used by OTP internal CI label Jun 17, 2025
@Mikaka27 Mikaka27 requested a review from Copilot July 21, 2025 08:38
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in Diameter transport modules where the message_cb callback is not properly updated for subsequent ack events when a new callback is returned during a send event.

  • Reorders the execution of message sending and action processing to ensure updated callbacks are used
  • Ensures that when message_cb returns a new callback during a send event, the ack event uses the updated callback instead of the original one

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/diameter/src/transport/diameter_tcp.erl Changes order of operations in actions/3 to process remaining actions before sending message
lib/diameter/src/transport/diameter_sctp.erl Applies the same fix to SCTP transport for consistency

@u3s u3s removed the waiting waiting for changes/input from author label Jul 22, 2025
@Mikaka27
Copy link
Contributor

Hi, could you provide the argument why do you think this change is necessary? If I understand the code correctly this could break existing applications. There could be code written in a way that expects ack to land in old callback, and suddenly we will switch it, and possibly break something.

@Mikaka27 Mikaka27 added the waiting waiting for changes/input from author label Aug 4, 2025
@albertored
Copy link
Contributor Author

I think one of more valuable use cases of allowing to return a new callback is to support a sort of state.
When you return a new callback with same module and function but different arguments you are simply updating the state (the arguments) of your callback module. This works only if the callback change is applied immediately and the subsequent call has the update argument. This is indeed what happen almost every time beside the specific case of this bug report.

A part for the specific state use case I think normalizing it as suggested would make the API more coherent and easy to be used, the fact that for that specific situation the callback is not immediately changed is counterintuitive and can lead to errors difficult to spot.

Please feel free to ask more if the motivation is not sufficiently clear, I can provide an example of where/how it is failing

@Mikaka27 Mikaka27 removed the waiting waiting for changes/input from author label Aug 12, 2025
@Mikaka27
Copy link
Contributor

I think one of more valuable use cases of allowing to return a new callback is to support a sort of state. When you return a new callback with same module and function but different arguments you are simply updating the state (the arguments) of your callback module. This works only if the callback change is applied immediately and the subsequent call has the update argument. This is indeed what happen almost every time beside the specific case of this bug report.

A part for the specific state use case I think normalizing it as suggested would make the API more coherent and easy to be used, the fact that for that specific situation the callback is not immediately changed is counterintuitive and can lead to errors difficult to spot.

Please feel free to ask more if the motivation is not sufficiently clear, I can provide an example of where/how it is failing

Hi, I think you're right, could you rebase your branch from tag 'patch-base-27' and add tests to this branch? I've come up with a testcase that detects this problem here: master...Mikaka27:otp:michal/diameter/call-message-cb-with-updated-callback

You can use it, unless you have a better test case that can be used instead, thanks :)

@Mikaka27 Mikaka27 removed the testing currently being tested, tag is used by OTP internal CI label Aug 13, 2025
@IngelaAndin IngelaAndin added the waiting waiting for changes/input from author label Aug 26, 2025
@Mikaka27 Mikaka27 removed the waiting waiting for changes/input from author label Aug 27, 2025
@Mikaka27 Mikaka27 changed the base branch from master to maint August 27, 2025 08:45
@Mikaka27
Copy link
Contributor

Mikaka27 commented Aug 27, 2025

Hi, I've added the tests and changed the target branch. I need to test this on our CI overnight.

@Mikaka27 Mikaka27 added the testing currently being tested, tag is used by OTP internal CI label Aug 27, 2025
@albertored
Copy link
Contributor Author

Thank you and sorry but it is a very busy period forme

@Mikaka27 Mikaka27 merged commit ac3e372 into erlang:maint Sep 1, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants