Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #120
What
"Auto-Update tonies.json" only updates at startup. This adds the task for the periodic check that was missing, and makes the check cheap, which was the condition for #136: an unchanged tonies.json is not downloaded again.
server_initrunstonies_updateeverycore.tonies_json_update_intervalhours (new setting, default 6, 0 = only at startup as before) whilecore.tonies_json_auto_updateis on. It looks at the clock and the settings every 5 seconds, so a changed interval or a shutdown does not wait.tonies_updateremembers the ETag of the tonies.json it downloaded and sends it asIf-None-Matchon the next update. GitHub answers an unchanged file with304and no body, also through the redirect from api.revvox.de (the header is part of the callback context and goes along with the redirect). On 304 it logs "tonies.json is unchanged, keeping it" and reloads nothing. The ETag is kept in memory only, so the update at startup downloads the whole file as before.web_requestgets one optional header,If-None-Match, from a newif_none_matchfield ofcbr_ctx_t. Everycbr_ctx_tis zeroed (fillBaseCtx,{0}), so other callers send nothing new./api/toniesJsonUpdatecan overlap, and two downloads into the same temp file would mix. A second one returnsERROR_ALREADY_RUNNINGand logs "tonies.json is being updated already". The flag is set underMUTEX_TONIES_JSON_CACHEbut the mutex is not held during the download, so the mutex manager does not warn about a long lock.tonies_deinit,cache_deinitandmutex_manager_deinit; otherwise a download that ends after them would reload the catalogue with a destroyed mutex. Onceinternal.exitis set,tonies_updaterefuses to start ("Not updating tonies.json while teddyCloud shuts down"), and the task checks it after each wait, so no update starts during shutdown. This also covers/api/toniesJsonUpdateshortly before an exit, which can hit the same today.tonies_deinitfrees the shared ones, which saving tonies.custom.json or/api/toniesJsonReloadmay do while a download runs.Tested (Linux debug build with ASan and UBSan, in Docker; interval switched to minutes in the test build only)
/api/toniesJsonUpdateat once/api/triggerExitwhile a full download runs/api/toniesJsonUpdateafter/api/triggerExitNo sanitizer reports in any of them.
Not in this PR
The lookups (
tonies_byAudioIdand others) return pointers into the cache that callers use after the mutex is released, and a reload frees that cache. That race exists today with/api/toniesJsonUpdate; a periodic check reloads only when the catalogue changed, a few times a week. I would follow up with a separate PR that keeps the replaced cache until the next reload.