Skip to content

Commit b34fc13

Browse files
author
bors-servo
authored
Auto merge of servo#24401 - gterzian:ensure_done_chan_is_none_when_revalidating, r=jdm
Fetch: ensure consistency between response, done-chan, and cache state. This ensures that when a cached response is not used because it requires revalidation, the done chan is set back to `None`(since the cache might have set it to `Some` when constructing the response requiring revalidation). <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix servo#24399 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24401) <!-- Reviewable:end -->
2 parents 3d529b1 + bb1fa88 commit b34fc13

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

components/net/http_loader.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,20 +1092,6 @@ fn http_network_or_cache_fetch(
10921092
response_from_cache.needs_validation,
10931093
),
10941094
};
1095-
if cached_response.is_none() {
1096-
// Ensure the done chan is not set if we're not using the cached response,
1097-
// as the cache might have set it to Some if it constructed a pending response.
1098-
*done_chan = None;
1099-
1100-
// Update the cache state, incrementing the pending store count,
1101-
// or starting the count.
1102-
if let HttpCacheEntryState::PendingStore(i) = *state {
1103-
let new = i + 1;
1104-
*state = HttpCacheEntryState::PendingStore(new);
1105-
} else {
1106-
*state = HttpCacheEntryState::PendingStore(1);
1107-
}
1108-
}
11091095
if needs_revalidation {
11101096
revalidating_flag = true;
11111097
// Substep 5
@@ -1124,6 +1110,20 @@ fn http_network_or_cache_fetch(
11241110
// Substep 6
11251111
response = cached_response;
11261112
}
1113+
if response.is_none() {
1114+
// Ensure the done chan is not set if we're not using the cached response,
1115+
// as the cache might have set it to Some if it constructed a pending response.
1116+
*done_chan = None;
1117+
1118+
// Update the cache state, incrementing the pending store count,
1119+
// or starting the count.
1120+
if let HttpCacheEntryState::PendingStore(i) = *state {
1121+
let new = i + 1;
1122+
*state = HttpCacheEntryState::PendingStore(new);
1123+
} else {
1124+
*state = HttpCacheEntryState::PendingStore(1);
1125+
}
1126+
}
11271127
}
11281128
}
11291129
// Notify the next thread waiting in line, if there is any.
@@ -1223,6 +1223,9 @@ fn http_network_or_cache_fetch(
12231223
.map_or(false, |s| s.0 == StatusCode::NOT_MODIFIED)
12241224
{
12251225
if let Ok(mut http_cache) = context.state.http_cache.write() {
1226+
// Ensure done_chan is None,
1227+
// since the network response will be replaced by the revalidated stored one.
1228+
*done_chan = None;
12261229
response = http_cache.refresh(&http_request, forward_response.clone(), done_chan);
12271230
wait_for_cached_response(done_chan, &mut response);
12281231
}

0 commit comments

Comments
 (0)