-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Cleanup CASESession and PASESession lifetime #13357
Conversation
PR #13357: Size comparison from 36a759d to 6dc903d Increases (13 builds for efr32, k32w, linux, p6, qpg, telink)
Decreases (2 builds for linux)
Full report (14 builds for efr32, k32w, linux, p6, qpg, telink)
|
In fact, maybe |
It would be my preference not to do this in this PR. |
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
Co-authored-by: Boris Zbarsky <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, but let's do a followup to consolidate the must-be-done-just-so code.
PR #13357: Size comparison from 36a759d to 3d04424 Increases above 0.2%:
Increases (17 builds for efr32, k32w, linux, mbed, p6, qpg, telink)
Decreases (2 builds for linux)
Full report (19 builds for efr32, k32w, linux, mbed, p6, qpg, telink)
|
@msandstedt - conflicts |
Conflicts are fixed. Now just need to fix top of tree... |
PR #13357: Size comparison from 585cdcb to caf19ce Increases (13 builds for efr32, k32w, linux, p6, qpg, telink)
Decreases (2 builds for linux)
Full report (14 builds for efr32, k32w, linux, p6, qpg, telink)
|
PR #13357: Size comparison from c25c4b3 to 87990b6 Increases (23 builds for efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
Decreases (2 builds for linux)
Full report (31 builds for efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
|
The fix in project-chip#12794 means that the CASESession and PASESession objects do not need to persist for ExchangeMessageDispatch::SendMessage to succeed at the final ACK of session establishment. Instead, SendMessage uses the SessionEstablishmentExchangeDispatch global singleton. This means we can address 13146 such that CASESession and PASESession may actually be freed or reused when completion callbacks fire. This will only work, however, if these objects clear themselves as delegates for their exchange contexts when discarding references to these. This commit does so. This commit also reorders all calls to mDelegate->OnSessionEstablished and mDelegate->OnSessionEstablishmentError to occur last in any given method in case mDelegate frees or reuses the CASESession or PASESession objects on execution of these completion callbacks. With this, we can remove the code in the OperationalDeviceProxy that defers release of the CASESession object until after an iteration of the event loop. Now when OnSessionEstablished fires, the CASESession can be reused or discarded immediately.
Problem
CASESession and PASESession objects cannot be freed or reused when OnSessionEstablished and OnSessionEstablishmentError delegate methods are executed. Instead, historically, code needed to wait for one more iteration of the event loop before freeing or reusing these objects.
This was in part due to the problem identified in and fixed by #12794, where these objects needed to persist in order for the ExchangeMessageDispatch::SendMessage call for the final ACK of session establishment to be sent. Instead, with #12794, SendMessage uses the SessionEstablishmentExchangeDispatch global singleton.
But there are two other things that prevent immediate free or reuse of the CASESession and PASESession objects on execution of completion callbacks: these objects clear their references to their exchange contexts at completion, but do not clear themselves as delegates to their exchange contexts. The object's methods can also continue to access instance memory after execution of the callbacks.
Change overview
This commit adds code to CASESession and PASESession to always clear themselves as delegates to their exchange contexts before clearing their references to their exchange contexts, and reorders calls to mDelegate->OnSessionEstablished and mDelegate->OnSessionEstablishmentError to occur last in any given method
in case mDelegate frees or reuses the CASESession or PASESession objects on execution of the completion callbacks.
Additionally, this removes the code in the OperationalDeviceProxy that was deferring release of the CASESession object until after an iteration of the event loop. Now when OnSessionEstablished fires, the CASESession can be reused or discarded immediately.
Fixes #13146
Testing
TestCASESession, TestPASESession and all other unit tests pass. We also expect asan to show clean CI runs with this.
This was also manually tested and seen to fix #13146 in the original feature branch for #13294 where this problem had first been identified.