Skip to content

Commit 1fdd217

Browse files
Cancel the SRP timer if we have resolved on the SRP domain but the kD… (#32948)
* Cancel the SRP timer if we have resolved on the SRP domain but the kDNSServiceFlagsMoreComing is set indicating there are more results coming * Update src/platform/Darwin/DnssdImpl.cpp Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> * Addressed review comments --------- Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 15f2c49 commit 1fdd217

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/platform/Darwin/DnssdContexts.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,7 @@ ResolveContext::ResolveContext(DiscoverNodeDelegate * delegate, chip::Inet::IPAd
492492

493493
ResolveContext::~ResolveContext()
494494
{
495-
if (isSRPTimerRunning)
496-
{
497-
CancelSRPTimer();
498-
}
495+
CancelSRPTimerIfRunning();
499496
}
500497

501498
void ResolveContext::DispatchFailure(const char * errorStr, CHIP_ERROR err)
@@ -647,10 +644,14 @@ void ResolveContext::SRPTimerExpiredCallback(chip::System::Layer * systemLayer,
647644
sdCtx->Finalize();
648645
}
649646

650-
void ResolveContext::CancelSRPTimer()
647+
void ResolveContext::CancelSRPTimerIfRunning()
651648
{
652-
DeviceLayer::SystemLayer().CancelTimer(SRPTimerExpiredCallback, static_cast<void *>(this));
653-
ChipLogProgress(Discovery, "SRP resolve timer for %s cancelled; resolve timed out", instanceName.c_str());
649+
if (isSRPTimerRunning)
650+
{
651+
DeviceLayer::SystemLayer().CancelTimer(SRPTimerExpiredCallback, static_cast<void *>(this));
652+
ChipLogProgress(Discovery, "SRP resolve timer for %s cancelled; resolve timed out", instanceName.c_str());
653+
isSRPTimerRunning = false;
654+
}
654655
}
655656

656657
CHIP_ERROR ResolveContext::OnNewAddress(const InterfaceKey & interfaceKey, const struct sockaddr * address)

src/platform/Darwin/DnssdImpl.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,13 @@ static void OnGetAddrInfo(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t i
272272

273273
if (flags & kDNSServiceFlagsMoreComing)
274274
{
275+
// If we now don't need to have a timer while we wait for SRP results, ensure that there is no such
276+
// timer running. Otherwise the timer could fire before we get the rest of the results that flags
277+
// say are coming, and trigger a finalize before we have all the data that is already available.
278+
if (!sdCtx->shouldStartSRPTimerForResolve)
279+
{
280+
sdCtx->CancelSRPTimerIfRunning();
281+
}
275282
return;
276283
}
277284

src/platform/Darwin/DnssdImpl.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ struct ResolveContext : public GenericContext
297297
*/
298298
static void SRPTimerExpiredCallback(chip::System::Layer * systemLayer, void * callbackContext);
299299

300+
/**
301+
* @brief Cancels the timer that was started to wait for the resolution on the kSRPDot domain to happen.
302+
*
303+
*/
304+
void CancelSRPTimerIfRunning();
305+
300306
private:
301307
/**
302308
* Try reporting the results we got on the provided interface index.
@@ -306,12 +312,6 @@ struct ResolveContext : public GenericContext
306312
bool TryReportingResultsForInterfaceIndex(uint32_t interfaceIndex, const std::string & hostname, bool isSRPResult);
307313

308314
bool TryReportingResultsForInterfaceIndex(uint32_t interfaceIndex);
309-
310-
/**
311-
* @brief Cancels the timer that was started to wait for the resolution on the kSRPDot domain to happen.
312-
*
313-
*/
314-
void CancelSRPTimer();
315315
};
316316

317317
} // namespace Dnssd

0 commit comments

Comments
 (0)