Skip to content

Add listener to events.on("error") - #1221

Open
julienmalard wants to merge 6 commits into
orbitdb:mainfrom
julienmalard:patch-1
Open

Add listener to events.on("error")#1221
julienmalard wants to merge 6 commits into
orbitdb:mainfrom
julienmalard:patch-1

Conversation

@julienmalard

Copy link
Copy Markdown
Contributor

Node.js, by default, throws an error if an EventEmitter emits an "error" event and no other listener is configured. This causes OrbitDB to crash the main thread on Node.js whenever a libp2p error occurs during synchronisation.

julienmalard added a commit to julienmalard/orbitdb that referenced this pull request Feb 16, 2025
julienmalard added a commit to julienmalard/orbitdb that referenced this pull request Feb 17, 2025
@haydenyoung

Copy link
Copy Markdown
Member

Adding for reference; this node issue is documented here.

@NiKrause

Copy link
Copy Markdown
Contributor

I don't really understand the fix. The question is, do I only need to add error event listener somewhere, or will that be added directly in OrbitDB, in my app, or I am getting something completely wrong.

@julienmalard

Copy link
Copy Markdown
Contributor Author

@silkroadnomad This is due to the behaviour of Node.js documented here which throws an error when EventEmittor.emit("error") is called with no previously registered listeners. Until this PR is resolved, if you add a listener elsewhere in your app (to the db.events object), any errors will not result in a process exit.

@NiKrause

NiKrause commented Apr 10, 2025

Copy link
Copy Markdown
Contributor

This is very good news Julien!

Thanks so much for figuring that out. This issue led to db crashes, in my opinion, which made it inaccessible and causes a lot of headaches.

I am wondering if an interrupted internet connection during an ongoing longer replication / bigger db sync now just leads to an incomplete sync or a sync that is rolled back again or still in a corrupted level db. Also. if I click a button to load a remote db, it would sync and if I click quickly to load other db's a view times, it would probably not finish the replication which then leads to "some sort of stream ended pushable errors" (but now without the app crash)

In case an error occurs, however, it is necessary to close the db so nothing bad happens.

I am still tapping a bit in the dark here. But it's good we are having all the same challenges.

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.

3 participants