Fix test for races with multiple parallel requests (#3891)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Nathan Gass
2025-10-16 20:00:05 +02:00
committed by GitHub
parent d8080ee5dc
commit 8107475458
2 changed files with 6 additions and 3 deletions

View File

@@ -82,6 +82,7 @@ protected:
private:
std::optional<std::string> url;
std::unique_ptr<AsyncRequest> req;
std::atomic<uint64_t> requestGeneration{0};
std::shared_ptr<Scheduler> sequencedScheduler;
mapbox::base::WeakPtrFactory<Source> weakFactory{this};
// Do not add members here, see `WeakPtrFactory`

View File

@@ -99,10 +99,12 @@ void GeoJSONSource::loadDescription(FileSource& fileSource) {
return makeMutable<Impl>(current, std::move(geoJSONData));
},
/* onImplReady */
[this, self = makeWeakPtr(), capturedReq = req.get()](Immutable<Source::Impl> newImpl) {
assert(capturedReq);
[this, self = makeWeakPtr(), capturedReqGeneration = ++requestGeneration](
Immutable<Source::Impl> newImpl) {
assert(capturedReqGeneration);
if (auto guard = self.lock(); self) {
if (capturedReq == req.get()) { // If a new request is being processed, ignore this impl.
if (capturedReqGeneration ==
requestGeneration) { // If a new request is being processed, ignore this impl.
baseImpl = std::move(newImpl);
loaded = true;
observer->onSourceLoaded(*this);