Skip to content

fix(iot-dev): Preserve response callback context#1847

Open
arnabnandy7 wants to merge 1 commit into
Azure:mainfrom
arnabnandy7:fix/device-client-callbacks
Open

fix(iot-dev): Preserve response callback context#1847
arnabnandy7 wants to merge 1 commit into
Azure:mainfrom
arnabnandy7:fix/device-client-callbacks

Conversation

@arnabnandy7

Copy link
Copy Markdown

Checklist

Reference/Link to the issue solved with this PR (if any)

Fixes #1803

Description of the problem

For correlated device client operations such as getTwinAsync and updateReportedPropertiesAsync, onResponseReceived could be skipped in a race condition.

In IotHubTransport.onMessageReceived, the received message was added to the receive queue before the matching CorrelationCallbackContext was read from correlationCallbacks. Adding the message to the queue wakes the receive task, which may acknowledge the message and remove the correlation callback before onMessageReceived looks it up. When that happens, the response callback is never invoked.

Description of the solution

Capture the CorrelationCallbackContext before adding the received message to the receive queue. onResponseReceived now uses that saved context, so it still fires even if the receive task acknowledges the message and removes the callback entry immediately afterward.

Added a regression unit test that simulates the correlation callback being removed while the received message is queued, and verifies that onResponseReceived is still called.

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

Successfully merging this pull request may close these issues.

[Bug Report] device client's onResponseReceived calls could be missing

1 participant