* The put-off synthesis, under the locks a sync holds. Nothing to do when a * sync ran it meanwhile. When the file lock is taken by another process, * try again after the interval; `synthesis_pending` stays set throughout. * * It runs from a timer, so nothing above it catches a failure,
()
| 2008 | * here is logged and tried again after the interval, as lock contention is. |
| 2009 | */ |
| 2010 | private async runDeferredSynthesis(): Promise<void> { |
| 2011 | const retryLater = (): void => { |
| 2012 | if (!this.db.isOpen()) return; |
| 2013 | this.armDeferredSynthesis(parseSynthMinIntervalEnv(process.env.CODEGRAPH_SYNTH_MIN_INTERVAL_MS) ?? 1000); |
| 2014 | }; |
| 2015 | try { |
| 2016 | await this.indexMutex.withLock(async () => { |
| 2017 | if (this.queries.getMetadata('synthesis_pending') !== '1') return; |
| 2018 | try { |
| 2019 | this.fileLock.acquire(); |
| 2020 | } catch { |
| 2021 | retryLater(); |
| 2022 | return; |
| 2023 | } |
| 2024 | try { |
| 2025 | // A rebuild may have replaced the file meanwhile, as sync checks. |
| 2026 | this.reopenReplacedDatabase(); |
| 2027 | if (this.queries.getMetadata('synthesis_pending') !== '1') return; |
| 2028 | await this.synthesizeWithWalDeferred(); |
| 2029 | } finally { |
| 2030 | this.fileLock.release(); |
| 2031 | } |
| 2032 | }); |
| 2033 | } catch (err) { |
| 2034 | logWarn(`Put-off synthesis failed, trying again after the interval: ${err instanceof Error ? err.message : String(err)}`); |
| 2035 | retryLater(); |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | /** |
| 2040 | * The rebuild, with the WAL handling a sync gives it (#1231, #1248): a whole |
no test coverage detected