forge
Explore
Log in

Don't you dare go Hollow

Unknown service health parses, full directory read only after resync or error, photo ETag must match the asked version

Browse files at this commit

ecfdd29ae761dfa1c22db861eb48695a6797dd6fAhmet Kaan GümüşParent: 72a986d
  • fix
    • unknown service health parses, full directory read only after resync or error, photo ETag must match the asked version
Show full message
🐛 fix: unknown service health parses, full directory read only after resync or error, photo ETag must match the asked version
crates/in-web/src/directory.rsmodified+7 -4
@@ -204,7 +204,7 @@ pub async fn run(state: AppState, mut stop: watch::Receiver<bool>) {
204 if *stop.borrow() {204 if *stop.borrow() {
205 return;205 return;
206 }206 }
207- let pause = match round(&state, &oidc, needs_full, &mut stop).await {207+ let pause = match round(&state, &oidc, &mut needs_full, &mut stop).await {
208 Ok(Ended::Resync) => {208 Ok(Ended::Resync) => {
209 needs_full = true;209 needs_full = true;
210 backoff = BACKOFF_FIRST;210 backoff = BACKOFF_FIRST;
@@ -234,15 +234,18 @@ pub async fn run(state: AppState, mut stop: watch::Receiver<bool>) {
234 }234 }
235 }235 }
236 236
237-/// One round: a full fetch when one is due, then the stream from the stored cursor.237+/// One round: a full fetch when one is due, then the stream from the stored cursor. The flag is cleared
238+/// once the full fetch has applied, so a plain reconnect resumes from the cursor without reading the
239+/// whole listing again.
238 async fn round(240 async fn round(
239 state: &AppState,241 state: &AppState,
240 oidc: &OidcClient,242 oidc: &OidcClient,
241- needs_full: bool,243+ needs_full: &mut bool,
242 stop: &mut watch::Receiver<bool>,244 stop: &mut watch::Receiver<bool>,
243 ) -> Result<Ended, SyncError> {245 ) -> Result<Ended, SyncError> {
244- if needs_full {246+ if *needs_full {
245 full_sync(state, oidc).await?;247 full_sync(state, oidc).await?;
248+ *needs_full = false;
246 }249 }
247 follow(state, oidc, stop).await250 follow(state, oidc, stop).await
248 }251 }
crates/in-web/src/family.rsmodified+6 -3
@@ -33,9 +33,10 @@ pub struct FamilyLink {
33 pub name: String,33 pub name: String,
34 /// The origin the switcher opens.34 /// The origin the switcher opens.
35 pub url: String,35 pub url: String,
36- /// Whether `im`'s last probe of the service passed.36+ /// Whether `im`'s last probe of the service passed. `None` when `im` has not probed it yet: it sends
37+ /// `null` (or leaves the field out) before the first probe, and that is shown as unknown.
37 #[serde(default)]38 #[serde(default)]
38- pub healthy: bool,39+ pub healthy: Option<bool>,
39 }40 }
40 41
41 /// The body of `GET /api/v1/family`. Unknown fields are ignored.42 /// The body of `GET /api/v1/family`. Unknown fields are ignored.
@@ -135,11 +136,13 @@ mod tests {
135 {"key":"in","name":"Files","url":"https://in.example.com"},136 {"key":"in","name":"Files","url":"https://in.example.com"},
136 {"key":"bad","name":"Bad","url":"javascript:alert(1)"},137 {"key":"bad","name":"Bad","url":"javascript:alert(1)"},
137 {"key":"space","name":"S","url":"https://a.example/ x"},138 {"key":"space","name":"S","url":"https://a.example/ x"},
138- {"key":"iz","name":"<b>Board</b>","url":"https://iz.example.com"}139+ {"key":"iz","name":"<b>Board</b>","url":"https://iz.example.com","healthy":null,"checked_at":null}
139 ]}"#;140 ]}"#;
140 let links = parse_listing(body).unwrap();141 let links = parse_listing(body).unwrap();
141 let keys: Vec<&str> = links.iter().map(|l| l.key.as_str()).collect();142 let keys: Vec<&str> = links.iter().map(|l| l.key.as_str()).collect();
142 assert_eq!(keys, ["im", "iz"]);143 assert_eq!(keys, ["im", "iz"]);
144+ assert_eq!(links[0].healthy, Some(true));
145+ assert_eq!(links[1].healthy, None, "a null probe result is unknown");
143 assert_eq!(146 assert_eq!(
144 links[1].name, "<b>Board</b>",147 links[1].name, "<b>Board</b>",
145 "the name is kept and escaped when rendered"148 "the name is kept and escaped when rendered"
crates/in-web/src/pages/photo.rsmodified+9 -0
@@ -136,6 +136,15 @@ async fn fetch_photo(
136 let Some(content_type) = content_type else {136 let Some(content_type) = content_type else {
137 return Ok(None);137 return Ok(None);
138 };138 };
139+ // `im` answers with its newest photo when the version asked for is older than its own. Such bytes
140+ // must not be cached under the older version, so a mismatch is a retry, not a photo.
141+ let answered = response
142+ .headers()
143+ .get(ETAG)
144+ .and_then(|value| value.to_str().ok());
145+ if answered != Some(format!("\"p{version}\"").as_str()) {
146+ return Err(unavailable());
147+ }
139 // The size is checked while the body is read, so an oversized photo is never held whole.148 // The size is checked while the body is read, so an oversized photo is never held whole.
140 let bytes = match read_limited(response, MAX_PHOTO_BYTES).await {149 let bytes = match read_limited(response, MAX_PHOTO_BYTES).await {
141 Ok(Some(bytes)) => bytes,150 Ok(Some(bytes)) => bytes,