mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 07:36:10 -04:00
Add delays in MediumEnvironment::Stop() and test teardown to prevent use-after-free.
PiperOrigin-RevId: 819561773
This commit is contained in:
committed by
Copybara-Service
parent
6b567a8915
commit
9baa10cff3
@@ -71,6 +71,11 @@ constexpr absl::string_view kDeviceToken = "\x04\x20";
|
||||
constexpr absl::string_view kDeviceName = "device";
|
||||
constexpr absl::Duration kDefaultGattFetchDelay = absl::Milliseconds(200);
|
||||
|
||||
// Delay to allow background threads to complete during teardown.
|
||||
// This helps prevent use-after-free errors on resources like FakeClock
|
||||
// used by background tasks (e.g., in PendingJobRegistry).
|
||||
constexpr absl::Duration kTeardownDelay = absl::Milliseconds(400);
|
||||
|
||||
ByteArray CreateFastBleAdvertisement(const ByteArray& data,
|
||||
const ByteArray& device_token) {
|
||||
return ByteArray(BleAdvertisement(
|
||||
@@ -218,6 +223,9 @@ class DiscoveredPeripheralTrackerTest
|
||||
|
||||
void TearDown() override {
|
||||
discovered_peripheral_tracker_.reset();
|
||||
|
||||
// Add a small delay to allow background threads to complete.
|
||||
absl::SleepFor(kTeardownDelay);
|
||||
MediumEnvironment::Instance().Stop();
|
||||
NearbyFlags::GetInstance().ResetOverridedValues();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "absl/container/flat_hash_set.h"
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/escaping.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/time/time.h"
|
||||
|
||||
Reference in New Issue
Block a user