-
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
Fix ExchangeContext leaks #21846
Fix ExchangeContext leaks #21846
Conversation
4f0b8a2
to
c77a2cf
Compare
This makes some key fixes to the management of the ExchangeContext, specifically around how the WillSendMessage flag is set/cleared, as well as dealing with clean-up of the exchange in OnSessionReleased(). It also fixes some key bugs in ExchangeHolder around failure to release the ref on the exchange in certain scenarios as outlined in project-chip#21544 and project-chip#21632. Notably, the following fixes have been made to ExchangeContext: - Setting the WillSendMessage flag immediately in SendMessage and only clearing the WillSendMessage flag on actually having successfully sent a message in SendMessage. Otherwise, the holder is not able to infer that the ownership still resides with it on a SendMessage failure. - Not clearing the WillSendMessage flag in OnSessionReleased. This ensures the holder again can infer that it still has the ref and needs to give it up when OnExchangeClosing is called there-after. - Avoiding a double call of DoClose by checking if it is already closed. - Cleaning up OnSessionReleased logic to now correctly call Abort() in both the case where we're waiting for a response AND we're in the middle of received message dispatch (i.e we're in the middle of OnMessageReceived). This is a pre-existing bug where the closure of the exchange resulted in a leak due to MessageHandled() not quite cleaning up the EC later when the call unwinds. Tests: TestExchangeHolder has been buffed up to now exhaustively test permutations of send failure, session closure (both before and after message transmission) and calling WillSendMessage at all points along a 3 message transmission.
c77a2cf
to
5fd3b71
Compare
PR #21846: Size comparison from afd4ab7 to 5fd3b71 Increases above 0.2%:
Increases (39 builds for bl602, cc13x2_26x2, cyw30739, efr32, k32w, linux, mbed, p6, telink)
Decreases (6 builds for cc13x2_26x2)
Full report (39 builds for bl602, cc13x2_26x2, cyw30739, efr32, k32w, linux, mbed, p6, telink)
|
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.
I did not have time to carefully review TestExchangeHolder. Please make sure someone else does?
Approving so this is not blocked, but please make sure there "must-fix" items (the ones that have that phrase in the review comments) get fixed.
Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
PR #21846: Size comparison from 7870328 to d4bb284 Increases above 0.2%:
Increases (39 builds for bl602, cc13x2_26x2, cyw30739, efr32, k32w, linux, mbed, psoc6, telink)
Decreases (6 builds for cc13x2_26x2)
Full report (39 builds for bl602, cc13x2_26x2, cyw30739, efr32, k32w, linux, mbed, psoc6, telink)
|
…onditional in TestCommandInteraction
PR #21846: Size comparison from 3d7cc78 to 4146763 Increases (40 builds for bl602, cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, psoc6, telink)
Decreases (10 builds for cc13x2_26x2, linux)
Full report (41 builds for bl602, cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, mbed, psoc6, telink)
|
PR #21846: Size comparison from 3d7cc78 to 1c72c8e Increases above 0.2%:
Increases (43 builds for bl602, cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, telink)
Decreases (21 builds for cc13x2_26x2, esp32, linux, nrfconnect, psoc6, telink)
Full report (43 builds for bl602, cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, telink)
|
This makes some key fixes to the management of the
ExchangeContext
, specifically around how theWillSendMessage
flag is set/cleared, as well as dealing with clean-up of the exchange inOnSessionReleased()
. It also fixes some key bugs in ExchangeHolder around failure to release the ref on the exchange in certain scenarios as outlined in bugs #21544 and #21632.Notably, the following fixes have been made to
ExchangeContext
:Setting the
WillSendMessage
flag immediately inSendMessage
and only clearing the WillSendMessage flag on actually having successfully sent a message inSendMessage
. Otherwise, the holder is not able to infer that the ownership still resides with it on aSendMessage
failure.Not clearing the
WillSendMessage
flag in OnSessionReleased. This ensures the holder again can infer that it still has the ref and needs to give it up whenOnExchangeClosing
is called there-after.Avoiding a double call of
DoClose
by checking if it is already closed.Cleaning up
OnSessionReleased
logic to now correctly callAbort()
inboth the case where we're waiting for a response AND we're in the
middle of received message dispatch (i.e we're in the middle of
OnMessageReceived
). This is a pre-existing bug where the closure of the exchange resulted in a leak due toMessageHandled()
not quite cleaning up the EC later when the call unwinds.Tests:
TestExchangeHolder
has been buffed up to now exhaustively test permutations of send failure, session closure (both before and after message transmission) and calling WillSendMessage at all points along a3 message transmission.