diff --git a/src/protocols/echo/EchoClient.cpp b/src/protocols/echo/EchoClient.cpp index 829b867794291c..5311e07a22e4cb 100644 --- a/src/protocols/echo/EchoClient.cpp +++ b/src/protocols/echo/EchoClient.cpp @@ -29,6 +29,9 @@ namespace chip { namespace Protocols { namespace Echo { +// The Echo message timeout value in milliseconds. +constexpr uint32_t kEchoMessageTimeoutMsec = 800; + CHIP_ERROR EchoClient::Init(Messaging::ExchangeManager * exchangeMgr, SecureSessionHandle session) { // Error if already initialized. @@ -74,6 +77,8 @@ CHIP_ERROR EchoClient::SendEchoRequest(System::PacketBufferHandle && payload, Me return CHIP_ERROR_NO_MEMORY; } + mExchangeCtx->SetResponseTimeout(kEchoMessageTimeoutMsec); + // Send an Echo Request message. Discard the exchange context if the send fails. err = mExchangeCtx->SendMessage(MsgType::EchoRequest, std::move(payload), sendFlags.Set(Messaging::SendMessageFlags::kExpectResponse)); @@ -114,6 +119,7 @@ CHIP_ERROR EchoClient::OnMessageReceived(Messaging::ExchangeContext * ec, const void EchoClient::OnResponseTimeout(Messaging::ExchangeContext * ec) { + mExchangeCtx = nullptr; ChipLogProgress(Echo, "Time out! failed to receive echo response from Exchange: %p", ec); }