diff --git a/src/app/WriteClient.cpp b/src/app/WriteClient.cpp index 26699e402b76a3..8f2acc3adf3b93 100644 --- a/src/app/WriteClient.cpp +++ b/src/app/WriteClient.cpp @@ -244,21 +244,15 @@ CHIP_ERROR WriteClient::SendWriteRequest(SessionHandle session, System::Clock::T // Create a new exchange context. mpExchangeCtx = mpExchangeMgr->NewContext(session, this); VerifyOrExit(mpExchangeCtx != nullptr, err = CHIP_ERROR_NO_MEMORY); - if (session.IsGroupSession()) - { - // Exchange will be closed by WriteClientHandle::SendWriteRequest for group messages - err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::WriteRequest, std::move(packet), - Messaging::SendFlags(Messaging::SendMessageFlags::kNoAutoRequestAck)); - } - else - { - mpExchangeCtx->SetResponseTimeout(timeout); - err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::WriteRequest, std::move(packet), - Messaging::SendFlags(Messaging::SendMessageFlags::kExpectResponse)); - SuccessOrExit(err); - MoveToState(State::AwaitingResponse); - } + mpExchangeCtx->SetResponseTimeout(timeout); + + // kExpectResponse is ignored by ExchangeContext in case of groupcast + err = mpExchangeCtx->SendMessage(Protocols::InteractionModel::MsgType::WriteRequest, std::move(packet), + Messaging::SendFlags(Messaging::SendMessageFlags::kExpectResponse)); + SuccessOrExit(err); + + MoveToState(State::AwaitingResponse); exit: if (err != CHIP_NO_ERROR) @@ -266,6 +260,12 @@ CHIP_ERROR WriteClient::SendWriteRequest(SessionHandle session, System::Clock::T ClearExistingExchangeContext(); } + if (session.IsGroupSession()) + { + // Always shutdown on Group communication + Shutdown(); + } + return err; } @@ -361,7 +361,7 @@ CHIP_ERROR WriteClientHandle::SendWriteRequest(SessionHandle session, System::Cl // Transferring ownership of the underlying WriteClient to the IM layer. IM will manage its lifetime. // For groupcast writes, there is no transfer of ownership since the interaction is done upon transmission of the action - if (err == CHIP_NO_ERROR && !session.IsGroupSession()) + if (err == CHIP_NO_ERROR) { // Release the WriteClient without closing it. mpWriteClient = nullptr; diff --git a/src/messaging/ExchangeContext.cpp b/src/messaging/ExchangeContext.cpp index 257537017eb32b..62282598cb922d 100644 --- a/src/messaging/ExchangeContext.cpp +++ b/src/messaging/ExchangeContext.cpp @@ -129,11 +129,13 @@ CHIP_ERROR ExchangeContext::SendMessage(Protocols::Id protocolId, uint8_t msgTyp const Transport::PeerAddress * peerAddress = GetSessionHandle().GetPeerAddress(mExchangeMgr->GetSessionManager()); // Treat unknown peer address as "not UDP", because we have no idea whether // it's safe to do MRP there. - bool isUDPTransport = peerAddress && peerAddress->GetTransportType() == Transport::Type::kUdp; + bool isUDPTransport = peerAddress && peerAddress->GetTransportType() == Transport::Type::kUdp; + + // this check is ignored by the ExchangeMsgDispatch if !AutoRequestAck() bool reliableTransmissionRequested = isUDPTransport && !sendFlags.Has(SendMessageFlags::kNoAutoRequestAck); // If a response message is expected... - if (sendFlags.Has(SendMessageFlags::kExpectResponse)) + if (sendFlags.Has(SendMessageFlags::kExpectResponse) && !IsGroupExchangeContext()) { // Only one 'response expected' message can be outstanding at a time. if (IsResponseExpected()) diff --git a/src/messaging/ExchangeContext.h b/src/messaging/ExchangeContext.h index 1494056191e420..449a9ffcb5463d 100644 --- a/src/messaging/ExchangeContext.h +++ b/src/messaging/ExchangeContext.h @@ -76,6 +76,8 @@ class DLL_EXPORT ExchangeContext : public ReliableMessageContext, public Referen bool IsEncryptionRequired() const { return mDispatch->IsEncryptionRequired(); } + bool IsGroupExchangeContext() const { return (mSession.HasValue() && mSession.Value().IsGroupSession()); } + /** * Send a CHIP message on this exchange. *