connectedhomeip icon indicating copy to clipboard operation
connectedhomeip copied to clipboard

Clarify the message context life cycle management

Open yunhanw-google opened this issue 3 years ago • 4 comments

@bzbarsky-apple If I understand correctly, ProcessReportData will trigger the transmission of a StatusResponse, which is the final message in this exchange, resulting in the closure of the exchange automatically.

So this setting of the mpExchangeCtx to nullptr is purely for cleanliness, and serves no functional value right?

Originally posted by @mrjerryjohns in https://github.com/project-chip/connectedhomeip/pull/10061#discussion_r718804563

yunhanw-google avatar Sep 29 '21 19:09 yunhanw-google

From @bzbarsky-apple

The basic rules in the tree right now are as follows (see docs for ExchangeContext::SendMessage, ExchangeDelegate::OnResponseTimeout, ExchangeDelegate::OnMessageReceived On exchange timeout notification, need to call WillSendMessage or SendMessage or null out the pointer. In practice, null out the pointer. OnMessageReceived, same thing. In practice, if you are sending a response either send it or tell the exchange you plan to send it, otherwise null out the pointer. When doing a SendMessage, if it succeeds and you are not expecting a response null out the pointer. In all other cases, you are holding a ref to the exchange and should call Close if you want to close it. So for example, for subscriptions when you get the last message, the one you don't plan to respond to, just null out the pointer and the exchange will know it's the last message and close itself. On the other hand, if you are waiting for a response and you decide you want to kill off the transaction, you have to do the exchange closing yourself.

yunhanw-google avatar Sep 29 '21 20:09 yunhanw-google

this setting of the mpExchangeCtx to nullptr is purely for cleanliness, and serves no functional value right?? @bzbarsky-apple Except in cases where we have other code that tries to close it if non-null, yes

yunhanw-google avatar Sep 29 '21 20:09 yunhanw-google

The important part is that we're inside OnMessageReceived here, right? So yes, given that the exchange will close itself unless we send a message expecting a response or claim that we will...

What I don't understand is why the following ShutdownInternal is conditional on err being success. if ProcessReportData fails, what shuts us down?

bzbarsky-apple avatar Sep 29 '21 21:09 bzbarsky-apple

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Sep 16 '22 22:09 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Mar 23 '23 00:03 stale[bot]

This stale issue has been automatically closed. Thank you for your contributions.

stale[bot] avatar Apr 02 '23 05:04 stale[bot]