Skip to content

Commit

Permalink
fix: cannot read properies of undefined - disabling closing db
Browse files Browse the repository at this point in the history
  • Loading branch information
silkroadnomad committed Jan 21, 2025
1 parent 0432dac commit bf25c33
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
2 changes: 1 addition & 1 deletion relay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libp2p-relay",
"version": "0.12.47",
"version": "0.12.48",
"private": true,
"scripts": {
"start:no-restart": "node src/relay.js",
Expand Down
39 changes: 18 additions & 21 deletions relay/src/pinner/nameOpsFileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ export async function updateDailyNameOpsFile(
) {
try {
db = await getOrCreateDB(orbitdb);
if(!db) {
db = await getOrCreateDB(orbitdb);

}

for (const nameOp of nameOpUtxos) {
const docId = nameOp.txid;

Expand Down Expand Up @@ -191,23 +188,23 @@ export async function getLastNameOps(orbitdb, pageSize, from = 10, filter) {
export async function closeDB() {
if (!db || isClosing) return;

isClosing = true;
try {
await Promise.race([
db.close(),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Database close timeout')), DB_OPERATION_TIMEOUT)
)
]);
console.info(`Closed ${dbType} database successfully`);
} catch (error) {
console.error(`Error closing ${dbType} database:`, error);
// Force cleanup even if close fails
db = null;
} finally {
db = null;
isClosing = false;
}
// isClosing = true;
// try {
// await Promise.race([
// db.close(),
// new Promise((_, reject) =>
// setTimeout(() => reject(new Error('Database close timeout')), DB_OPERATION_TIMEOUT)
// )
// ]);
// console.info(`Closed ${dbType} database successfully`);
// } catch (error) {
// console.error(`Error closing ${dbType} database:`, error);
// // Force cleanup even if close fails
// db = null;
// } finally {
// db = null;
// isClosing = false;
// }
}

function applyFilter(nameOp, selectedFilter) {
Expand Down
6 changes: 3 additions & 3 deletions relay/src/pinner/scanBlockchainForNameOps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { processBlockAtHeight } from './blockProcessor.js';
import { updateDailyNameOpsFile, closeDB } from './nameOpsFileManager.js';
import { updateDailyNameOpsFile } from './nameOpsFileManager.js';
import {
getScanningState,
updateScanningState,
Expand Down Expand Up @@ -68,7 +68,7 @@ export async function scanBlockchainForNameOps(
);
} finally {
// Close DB when scanning is complete or if there's an error
await closeDB();
// await closeDB();
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ async function processBlocks(
)
);
} else {
console.info(`nameId or sanitizedValue not found for nameOp: ${nameOp.nameId} ${sanitizedValue} or not starting with ipfs://`, {nameOp});
// console.info(`nameId or sanitizedValue not found for nameOp: ${nameOp.nameId} ${sanitizedValue} or not starting with ipfs://`, {nameOp});
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions relay/src/relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import { createNode } from './nodeFactory.js';
import { setupPubsub } from './pubsubHandler.js';
import TipWatcher from './pinner/tipWatcher.js';
import { generateAndSaveKeyPair } from './utils/keypair.js';
import { cleanupLockFiles } from './utils/dbUtils.js';

// cleanupLockFiles()

export const CONTENT_TOPIC =
process.env.CONTENT_TOPIC || '/doichain-nfc/1/message/proto';
Expand Down

0 comments on commit bf25c33

Please sign in to comment.