-
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 leak in chip_im_initiator (Fix: #6915) #6918
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,10 @@ | |
#include <support/RandUtils.h> | ||
#include <support/logging/CHIPLogging.h> | ||
|
||
#if CONFIG_DEVICE_LAYER | ||
#include <platform/CHIPDeviceLayer.h> | ||
#endif | ||
|
||
using namespace chip::Encoding; | ||
using namespace chip::Inet; | ||
using namespace chip::System; | ||
|
@@ -94,6 +98,10 @@ CHIP_ERROR ExchangeManager::Init(SecureSessionMgr * sessionMgr) | |
|
||
CHIP_ERROR ExchangeManager::Shutdown() | ||
{ | ||
// TODO(#6931): Lock guard is a temporary solution. Proper solution should be post chip shutdown function into chip thread | ||
#if CONFIG_DEVICE_LAYER | ||
DeviceLayer::PlatformMgr().LockChipStack(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest moving DeviceLayer::PlatformMgr().LockChipStack() to the place where shutdown is called from the client thread, instead of within ExchangeManager::Shutdown() itself. You are trying to fix the problem in the case which Shutdown is called from a client thread, for the cases Shutdown() are called from CHIP main thread event loop(Which it should be), it will crash since chip lock is not recursive. |
||
#endif | ||
mReliableMessageMgr.Shutdown(); | ||
|
||
mContextPool.ForEachActiveObject([](auto * ec) { | ||
|
@@ -109,6 +117,9 @@ CHIP_ERROR ExchangeManager::Shutdown() | |
} | ||
|
||
mState = State::kState_NotInitialized; | ||
#if CONFIG_DEVICE_LAYER | ||
DeviceLayer::PlatformMgr().UnlockChipStack(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, move DeviceLayer::PlatformMgr().UnlockChipStack(); to the place Shutdown is called from the client thread |
||
#endif | ||
|
||
return CHIP_NO_ERROR; | ||
} | ||
|
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.
Wouldn't the real solution be to have this called in the main event loop task of the stack? Seems like the stack shutting itself down should be done from within the stack task itself, rather than being called from outside with a lock.
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.
The stack lock was introduced to protect CHIP event processing. Putting a chip lock here can only prevent CHIP from operating, but the problem here is the exchange is also released from the client thread.
How this change can prevent leaking?
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.
For IM, maybe it is ok, we just moved the logic to close the exchange in OnMessageReceived, but if the exchange closing also occurs in client thread, how this locking helps?