Skip to content

Eventemitter3 - #1227

Open
julienmalard wants to merge 1 commit into
orbitdb:mainfrom
julienmalard:eventemitter3
Open

julienmalard wants to merge 1 commit into
orbitdb:mainfrom
julienmalard:eventemitter3

Conversation

@julienmalard

@julienmalard julienmalard commented Apr 11, 2025 •

Copy link
Copy Markdown
Contributor

Fixes #1226 by preventing error events on an eventemitter with no error listeners from ending process execution.

@NiKrause

Copy link
Copy Markdown
Contributor

I tried this and it seems to help inside OrbitDB but as soon as it escalates up to Helia, e.g. as in my case, it tries to find a block which isn't neither available locally nor remotely, it throws a "All promises rejected" there.
So it still ends the main process, e.g. when working with voyager pinning service, when dealing with broken db's on one peer.

image

@julienmalard

Copy link
Copy Markdown
Contributor Author

Could you share the full stack trace @silkroadnomad ?
Thanks!

@NiKrause

NiKrause commented Apr 14, 2025 •

Copy link
Copy Markdown
Contributor

Here, this is one of the standard cases: mostly when a local DB, here on the Voyager pinning service, becomes inaccessible or corrupt (who knows why - I have some assumptions and theories, but no definite proofs), it cannot find the DB anymore on the local Helia instance. Then it tries to fetch it automatically via the block brokers / trustless gateways (of the IPFS network), but can't find it there because nobody was ever requesting it via one of those ipfs nodes (in my case). All promises get rejected because the CIDs cannot be found. I used my own OrbitDB fork, which is the same as the official one except that it includes your PR #1227.

In my opinion:
Databases get corrupted sometimes in browsers when replication is interrupted, e.g., during a network change or drop. A year ago, I was able to demonstrate this by switching a VPN on and off. This specific case was solved, i think, but from my understanding, it still happens more often or becomes riskier as a database grows larger, since the replication process then takes longer.

You can interrupt replication and break the database by switching off the network, closing a browser window, or changing code while developing locally (hot code swap). That is just my opinion and if I could proof one of those that would be it.
Planing on doing some e2e tests with two browsers now with some bigger db's in order to replicate one or the other assumed issue.

DB's can also break when it comes to network issues. In the past e.g. some libp2p transport bug in webrtc or yamux or what not, could interrupt the replication process and make the db in accessible. Those got fixed but it doesn't fix the main question: If a replication is interrupted and hence breaks some how, can we rollback the db automatically, as we notice a failed replication (corrupt db)?

Probably already before NodeJS is crashing because of an error, because it also happens in browsers out of my personal observations.

Interesting is, when a db becomes inaccessible it still replicates. So then in such case even the db on voyager or other pinning nodes can become inaccessible.

If you have any opinion on that, I'd be very glad to hear about it.

Unhandled Rejection at: Promise {
  <rejected> [AggregateError: All promises were rejected] {
    [errors]: [ [AggregateError], [AbortError] ]
  }
} reason: [AggregateError: All promises were rejected] {
  [errors]: [
    AggregateError: Unable to fetch raw block for CID bafyreif6eroxcufqshhnz7nsyepqntbtkup3ljle3crnf4gch7f2hvcqy4 from any gateway
        at TrustlessGatewayBlockBroker.retrieve (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/block-brokers/dist/src/trustless-gateway/broker.js:56:19)
        at processTicksAndRejections (node:internal/process/task_queues:105:5)
        at runNextTicks (node:internal/process/task_queues:69:3)
        at listOnTimeout (node:internal/timers:555:9)
        at process.processTimers (node:internal/timers:529:7)
        at async file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:353:31
        at async Promise.any (index 0)
        at async raceBlockRetrievers (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:349:16)
        at async NetworkedStorage.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:64:27)
        at async BlockStorage.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/storage.js:71:20) {
      [errors]: [Array]
    },
    AbortError: Want was aborted
        at raceEvent (file:///home/voyager/node_modules/.pnpm/[email protected]/node_modules/race-event/dist/src/index.js:129:19)
        at WantList.addEntry (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/bitswap/dist/src/want-list.js:79:37)
        at async Bitswap.want (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/bitswap/dist/src/bitswap.js:64:28)
        at async file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:353:31
        at async Promise.any (index 1)
        at async raceBlockRetrievers (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:349:16)
        at async NetworkedStorage.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:64:27)
        at async BlockStorage.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/storage.js:71:20)
        at async Object.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@le-space/orbitdb/src/storage/ipfs-block.js:62:19)
        at async Object.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@le-space/orbitdb/src/storage/composed.js:52:15) {
      type: 'aborted',
      code: 'ABORT_ERR'
    }
  ]
}
Unhandled rejection: [AggregateError: All promises were rejected] {
  [errors]: [
    AggregateError: Unable to fetch raw block for CID bafyreif6eroxcufqshhnz7nsyepqntbtkup3ljle3crnf4gch7f2hvcqy4 from any gateway
        at TrustlessGatewayBlockBroker.retrieve (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/block-brokers/dist/src/trustless-gateway/broker.js:56:19)
        at processTicksAndRejections (node:internal/process/task_queues:105:5)
        at runNextTicks (node:internal/process/task_queues:69:3)
        at listOnTimeout (node:internal/timers:555:9)
        at process.processTimers (node:internal/timers:529:7)
        at async file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:353:31
        at async Promise.any (index 0)
        at async raceBlockRetrievers (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:349:16)
        at async NetworkedStorage.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:64:27)
        at async BlockStorage.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/storage.js:71:20) {
      [errors]: [Array]
    },
    AbortError: Want was aborted
        at raceEvent (file:///home/voyager/node_modules/.pnpm/[email protected]/node_modules/race-event/dist/src/index.js:129:19)
        at WantList.addEntry (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/bitswap/dist/src/want-list.js:79:37)
        at async Bitswap.want (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/bitswap/dist/src/bitswap.js:64:28)
        at async file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:353:31
        at async Promise.any (index 1)
        at async raceBlockRetrievers (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:349:16)
        at async NetworkedStorage.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/utils/networked-storage.js:64:27)
        at async BlockStorage.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@helia/utils/dist/src/storage.js:71:20)
        at async Object.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@le-space/orbitdb/src/storage/ipfs-block.js:62:19)
        at async Object.get (file:///home/voyager/node_modules/.pnpm/@[email protected]/node_modules/@le-space/orbitdb/src/storage/composed.js:52:15) {
      type: 'aborted',
      code: 'ABORT_ERR'
    }
  ]
}

@haydenyoung

Copy link
Copy Markdown
Member

@silkroadnomad Is it possible to wrap this in a try...catch block to try and swallow the error?

@julienmalard

Copy link
Copy Markdown
Contributor Author

@silkroadnomad

Looking at this error, I have a few questions and thoughts:

  1. Is the error originating (initially) from the sync function in OrbitDb ? Or somewhere else entirely? If it's from elsewhere, this would indicate a new issue unrelated (at least directly) to this one.
  2. I'm wondering if it's really a database corruption issue. Could you share a minimal example of a corrupted database file so that I could try to examine it and hopefully reproduce the issue?
  3. Even if this is a database corruption in your case, I imagine that this issue could also arise with an uncorrupted database if a peer starts replicating a valid OrbitDb address for which all entries (or even the manifest) are not currently available on the IPFS network. As such, this is probably an error that many users will encounter.

@NiKrause

Copy link
Copy Markdown
Contributor

@haydenyoung yes, I did like that (mentioned) in #1226
process.on('uncaughtException', (err) => {
console.error('Uncaught Exception:', err)
// Don't exit the process
})

process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason)
// Don't exit the process
})

@NiKrause

NiKrause commented Apr 14, 2025 •

Copy link
Copy Markdown
Contributor

@julienmalard

  1. I think it is a chain reaction more or less related to on another e.g. the sync error is in my opinion one of the first symptoms, which leads to a corrupt db which then leads to blocks which cannot be found. You are somewhat right this is "a bit" unrelated, but still everything needs to play together. E.g. see this here: Voyager crash after UnexpectedEOFError: unexpected end of input voyager#94 and here AggregateError: All promises were rejected / AggregateError: Unable to fetch raw block for CID voyager#93

  2. I have some corrupt db's here, but need to figure out which one it was. I am also about to replicate it (hopefully this week). Please, give me some time for that.

  3. Absolutely, I totally agree on that. The "crash" can happen because of many different issues during a replication. Maybe we can all help to make some good ordering and put some light on it.

@haydenyoung

Copy link
Copy Markdown
Member

@haydenyoung yes, I did like that (mentioned) in #1226 process.on('uncaughtException', (err) => { console.error('Uncaught Exception:', err) // Don't exit the process })

process.on('unhandledRejection', (reason, promise) => { console.error('Unhandled Rejection at:', promise, 'reason:', reason) // Don't exit the process })

Does it help prevent the app from crashing?

@haydenyoung

Copy link
Copy Markdown
Member

@silkroadnomad if the issue has been isolated to Helia, it may be time to bring in their developers to help debug the problem.

@julienmalard

Copy link
Copy Markdown
Contributor Author

@silkroadnomad if the issue has been isolated to Helia, it may be time to bring in their developers to help debug the problem.

Sounds good. Could we consider merging this PR in the meantime? It seems that there are two issues, one here (in OrbitDb) and another in Helia that becomes apparent once this one is fixed.

@julienmalard

Copy link
Copy Markdown
Contributor Author

Does it help prevent the app from crashing?

For me, yes

@haydenyoung

Copy link
Copy Markdown
Member

If an app is crashing even after intercepting the error, it feels counterproductive to add more dependencies. Ideally, I think we want to replicate this error consistently and repeatedly, at least in the first instance. From there, we can build a more robust sync protocol.

@silkroadnomad Do you have any example code which we can use to replicate this problem on a consistent basis, even if it takes some time for the crash to happen? We can probably escalate this issue with the Helia devs if we have something to show them.

@NiKrause

Copy link
Copy Markdown
Contributor

@silkroadnomad Do you have any example code which we can use to replicate this problem on a consistent basis, even if it takes some time for the crash to happen? We can probably escalate this issue with the Helia devs if we have something to show them.

I am on it. Please bear with me. Fingers crossed!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OrbitDB crashes with UnexpectedEOFError when a peer joins and syncs

3 participants