* 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,
()
| 1957 | * here is logged and tried again after the interval, as lock contention is. |
| 1958 | */ |
| 1959 | private async runDeferredSynthesis(): Promise<void> { |
| 1960 | const retryLater = (): void => { |
| 1961 | if (!this.db.isOpen()) return; |
| 1962 | this.armDeferredSynthesis(parseSynthMinIntervalEnv(process.env.CODEGRAPH_SYNTH_MIN_INTERVAL_MS) ?? 1000); |
| 1963 | }; |
| 1964 | try { |
| 1965 | await this.indexMutex.withLock(async () => { |
| 1966 | if (this.queries.getMetadata('synthesis_pending') !== '1') return; |
| 1967 | try { |
| 1968 | this.fileLock.acquire(); |
| 1969 | } catch { |
| 1970 | retryLater(); |
| 1971 | return; |
| 1972 | } |
| 1973 | try { |
| 1974 | // A rebuild may have replaced the file meanwhile, as sync checks. |
| 1975 | this.reopenReplacedDatabase(); |
| 1976 | if (this.queries.getMetadata('synthesis_pending') !== '1') return; |
| 1977 | await this.synthesizeWithWalDeferred(); |
| 1978 | } finally { |
| 1979 | this.fileLock.release(); |
| 1980 | } |
| 1981 | }); |
| 1982 | } catch (err) { |
| 1983 | logWarn(`Put-off synthesis failed, trying again after the interval: ${err instanceof Error ? err.message : String(err)}`); |
| 1984 | retryLater(); |
| 1985 | } |
| 1986 | } |
| 1987 | |
| 1988 | /** |
| 1989 | * The rebuild, with the WAL handling a sync gives it (#1231, #1248): a whole |
no test coverage detected