* 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,
()
| 2031 | * here is logged and tried again after the interval, as lock contention is. |
| 2032 | */ |
| 2033 | private async runDeferredSynthesis(): Promise<void> { |
| 2034 | const retryLater = (): void => { |
| 2035 | if (!this.db.isOpen()) return; |
| 2036 | this.armDeferredSynthesis(parseSynthMinIntervalEnv(process.env.CODEGRAPH_SYNTH_MIN_INTERVAL_MS) ?? 1000); |
| 2037 | }; |
| 2038 | try { |
| 2039 | await this.indexMutex.withLock(async () => { |
| 2040 | if (this.queries.getMetadata('synthesis_pending') !== '1') return; |
| 2041 | try { |
| 2042 | this.fileLock.acquire(); |
| 2043 | } catch { |
| 2044 | retryLater(); |
| 2045 | return; |
| 2046 | } |
| 2047 | try { |
| 2048 | // A rebuild may have replaced the file meanwhile, as sync checks. |
| 2049 | this.reopenReplacedDatabase(); |
| 2050 | if (this.queries.getMetadata('synthesis_pending') !== '1') return; |
| 2051 | await this.synthesizeWithWalDeferred(); |
| 2052 | } finally { |
| 2053 | this.fileLock.release(); |
| 2054 | } |
| 2055 | }); |
| 2056 | } catch (err) { |
| 2057 | logWarn(`Put-off synthesis failed, trying again after the interval: ${err instanceof Error ? err.message : String(err)}`); |
| 2058 | retryLater(); |
| 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | /** |
| 2063 | * The rebuild, with the WAL handling a sync gives it (#1231, #1248): a whole |
no test coverage detected