From e749e220060d707b44eb81cd5170d1740d9fd758 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Thu, 19 Nov 2026 05:08:03 +0100 Subject: [PATCH] Prevent database from closing before biometrics have finished. --- src/actors.js | 25 +++++++++++++++++++++---- src/app.js | 11 ++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/actors.js b/src/actors.js index fd820993..f661dd6b 100755 --- a/src/actors.js +++ b/src/actors.js @@ -863,6 +863,8 @@ async function getActorNames(actorNames) { return actorsWithoutProfiles.rows.map((actor) => actor.name); } +const pendingBiometrics = new Set(); + async function storeProfiles(profiles) { const profilesWithAvatarIds = await associateAvatars(profiles); const actorIds = Array.from(new Set(profiles.map((profile) => profile.actorId))); @@ -872,10 +874,24 @@ async function storeProfiles(profiles) { await upsertProfiles(profilesWithAvatarIds); await interpolateProfiles(actorIds); - setBiometrics(Array.from(new Set(profiles.map((profile) => profile.actorId)))).catch((error) => { - // biometrics are courtesy, don't await - logger.error(`Biometrics failed: ${error.message}`); - }); + // biometrics are courtesy, don't hold up the scrape, but they must finish before the database pool is destroyed + const biometricsJob = setBiometrics(actorIds) + .catch((error) => { + logger.error(`Biometrics failed: ${error.message}`); + }) + .finally(() => { + pendingBiometrics.delete(biometricsJob); + }); + + pendingBiometrics.add(biometricsJob); +} + +async function waitForBiometrics() { + if (pendingBiometrics.size > 0) { + logger.info('Waiting for biometrics to finish'); + } + + await Promise.all(Array.from(pendingBiometrics)); } async function scrapeActors(argNames) { @@ -1261,4 +1277,5 @@ module.exports = { scrapeActors, searchActors, toBaseActors, + waitForBiometrics, }; diff --git a/src/app.js b/src/app.js index fdd91afd..ee783c33 100755 --- a/src/app.js +++ b/src/app.js @@ -19,7 +19,14 @@ const fetchUpdates = require('./updates'); const { fetchScenes, fetchMovies } = require('./deep'); const { storeScenes, storeMovies, associateMovieScenes } = require('./store-releases'); const { updateSceneSearch, updateMovieSearch } = require('./update-search'); -const { scrapeActors, deleteActors, flushActors, flushProfiles, interpolateProfiles } = require('./actors'); +const { + scrapeActors, + deleteActors, + flushActors, + flushProfiles, + interpolateProfiles, + waitForBiometrics, +} = require('./actors'); const { flushEntities } = require('./entities'); const { deleteScenes, deleteMovies, flushScenes, flushMovies, flushBatches } = require('./releases'); const { flushOrphanedMedia, detachReleaseMedia, detachEntityReleaseMedia } = require('./media'); @@ -278,6 +285,8 @@ async function init() { await unprint.closeAllBrowsers(); await unprint.closeAgents(); + await waitForBiometrics(); + knex.destroy(); redis.destroy();