Skip to content

Commit e30cd1c

Browse files
Handle the output event of type TransferSession::OutputEventType::kIn… (#37324)
* Handle the output event of type TransferSession::OutputEventType::kInternalError in the ProcessOuputEvents processing loop - The transfer session state machine generates an output event of type TransferSession::OutputEventType::kInternalError in certain error scenarios which put the transfer session in a bad state and when that happens, we need to unwind the processing loop for events and clean up. * Update src/protocols/bdx/AsyncTransferFacilitator.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Address review comments * Update src/protocols/bdx/AsyncTransferFacilitator.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> --------- Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 92f71c4 commit e30cd1c

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/protocols/bdx/AsyncTransferFacilitator.cpp

+22-8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ void AsyncTransferFacilitator::ProcessOutputEvents()
6363
mTransfer.GetNextAction(outEvent);
6464
while (outEvent.EventType != TransferSession::OutputEventType::kNone)
6565
{
66+
67+
// If the transfer session state machine generates an event of type TransferSession::OutputEventType::kInternalError,
68+
// indicating that the session is in a bad state, it will keep doing that thereafter.
69+
//
70+
// So stop trying to process events, and go ahead and destroy ourselves to clean up the transfer.
71+
if (outEvent.EventType == TransferSession::OutputEventType::kInternalError)
72+
{
73+
mDestroySelfAfterProcessingEvents = true;
74+
break;
75+
}
76+
6677
if (outEvent.EventType == TransferSession::OutputEventType::kMsgToSend)
6778
{
6879
CHIP_ERROR err = SendMessage(outEvent.msgTypeData, outEvent.MsgData);
@@ -170,22 +181,25 @@ void AsyncResponder::NotifyEventHandled(const TransferSession::OutputEventType e
170181
ChipLogDetail(BDX, "NotifyEventHandled : Event %s Error %" CHIP_ERROR_FORMAT,
171182
TransferSession::OutputEvent::TypeToString(eventType), status.Format());
172183

173-
// If this is the end of the transfer (whether a clean end, or some sort of error condition), ensure that
174-
// we destroy ourselves after processing any output events that might have been generated by
175-
// the transfer session to handle end-of-transfer (e.g. in some error conditions it might want to send
176-
// out a status report).
184+
// If this is the end of the transfer (whether a clean end, or some sort of error condition), ensure
185+
// that we destroy ourselves after unwinding the processing loop in the ProcessOutputEvents API.
186+
// We can ignore the status for these output events because none of them are supposed to result in
187+
// us sending a StatusReport, and that's all we use the status for.
188+
//
189+
// In particular, for kTransferTimeout, kAckEOFReceived, and kStatusReceived per spec we
190+
// are not supposed to reply with a StatusReport. And for kInternalError the state machine
191+
// is in an unrecoverable state of some sort, and we should stop trying to make use of it.
177192
if (eventType == TransferSession::OutputEventType::kAckEOFReceived ||
178193
eventType == TransferSession::OutputEventType::kInternalError ||
179194
eventType == TransferSession::OutputEventType::kTransferTimeout ||
180195
eventType == TransferSession::OutputEventType::kStatusReceived)
181196
{
182197
mDestroySelfAfterProcessingEvents = true;
183198
}
184-
185-
// If there was an error handling the output event, this should notify the transfer object to abort transfer so it can send a
186-
// status report across the exchange when we call ProcessOutputEvents below.
187-
if (status != CHIP_NO_ERROR)
199+
else if (status != CHIP_NO_ERROR)
188200
{
201+
// If there was an error handling the output event, this should notify the transfer object to abort transfer
202+
// so it can send a status report across the exchange when we call ProcessOutputEvents below.
189203
mTransfer.AbortTransfer(GetBdxStatusCodeFromChipError(status));
190204
}
191205

src/protocols/bdx/AsyncTransferFacilitator.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ class AsyncTransferFacilitator : public Messaging::ExchangeDelegate
7272
*/
7373
virtual void DestroySelf() = 0;
7474

75-
// Calling ProcessOutputEvents can destroy this object before the call returns.
75+
/**
76+
* Calling ProcessOutputEvents can destroy this object before the call returns.
77+
*/
7678
void ProcessOutputEvents();
7779

7880
// The transfer session corresponding to this AsyncTransferFacilitator object.

0 commit comments

Comments
 (0)