Skip to content

OrbitDB crashes with UnexpectedEOFError when a peer joins and syncs #1226

Closed

Description

@PradaJoaquin
  • Versions:

    • @orbitdb/core: 2.5.0
    • helia: 5.3.0
    • libp2p: 2.8.2
  • Platform: Linux

Hello! We're building an application using OrbitDB and occasionally encountering a crash when a peer joins a database. Unfortunately, we haven't been able to consistently reproduce the issue, but it happens shortly after a peer connects and joins the DB. It does not happen every time a peer joins, only occasionally.

Here’s the relevant log and stack trace:

12D3KooWK7Ps4v7rinUCVchq9wf2aoEpNGWq3aKTQQcYjF24Mccz joined
file:///home/joaquin/nodo-test/node_modules/it-byte-stream/dist/src/index.js:94
                        throw new UnexpectedEOFError('unexpected end of input');
                              ^

UnexpectedEOFError: unexpected end of input
    at Object.read (file:///home/joaquin/nodo-test/node_modules/it-byte-stream/dist/src/index.js:94:31)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Object.read (file:///home/joaquin/nodo-test/node_modules/it-length-prefixed-stream/dist/src/index.js:45:37)
    at async read (file:///home/joaquin/nodo-test/node_modules/@libp2p/multistream-select/dist/src/multistream.js:22:17)
    at async Module.readString (file:///home/joaquin/nodo-test/node_modules/@libp2p/multistream-select/dist/src/multistream.js:33:17)
    at async Module.select (file:///home/joaquin/nodo-test/node_modules/@libp2p/multistream-select/dist/src/select.js:72:20)
    at async ConnectionImpl.newStream [as _newStream] (file:///home/joaquin/nodo-test/node_modules/libp2p/dist/src/upgrader.js:331:50)
    at async ConnectionImpl.newStream (file:///home/joaquin/nodo-test/node_modules/libp2p/dist/src/connection/index.js:94:24)
    at async task (file:///home/joaquin/nodo-test/node_modules/@orbitdb/core/src/sync.js:194:26)
    at async file:///home/joaquin/nodo-test/node_modules/p-queue/dist/index.js:230:36
Emitted 'error' event at:
    at task (file:///home/joaquin/nodo-test/node_modules/@orbitdb/core/src/sync.js:201:20)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async file:///home/joaquin/nodo-test/node_modules/p-queue/dist/index.js:230:36 {
  code: 'ERR_UNEXPECTED_EOF'
}

This error always occurs right after a peer joins the database — we see the joined log line, which fires with the join event, and then the application crashes almost immediately.

It seems related to the sync process or a stream error when establishing the connection.

We've been stuck for a while and we'd appreciate any help or advice on how to solve this. Thank you in advance!

Activity

  1. haydenyoung commented on Apr 10, 2025

    @haydenyoung
    Member

    Sounds like an issue with the underlying libp2p streams. I have been told there are some updates to libp2p which could solve this.

    Crashing could potentially be solved by #1221 so at least your app could recover.

    I will check both these updates and maybe bundle into a PR which you can test. If it solves the issue for you then we can merge back in to main.

  2. NiKrause commented on Apr 13, 2025

    @NiKrause
    Contributor

    @PradaJoaquin I had something similar orbitdb/voyager#94 working on Voyager pinning server on NodeJS! (I guess your peer also works on NodeJS and not in a browser?)

    Can you check if after such a crash the db is still readable on that peer (and the other)?

    I added the PR #1227 of @julienmalard but it did not prevent escalating errors up to Helia but then added some:

    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
     })
    

    to the main process, which helps me out for now.

    NiKrause/voyager@2441f41#diff-b25843cbd8732e59cf896fa970d3feb143325563b1aa8731ac2123285c2c531bL4-R117

  3. NiKrause commented on Apr 30, 2025

    @NiKrause
    Contributor

    I have to add something to this situation: When ever it happens, my websocket and/or webrtc-direct connections to that peer are also ending. (even when caught via uncaughtException / unhandledRejection) on the main process.

    It is possible that this is a Helia issue. The question is: can we reproduce that issue on a Helia example project in such extend without adding OrbitDB to the play!

  4. NiKrause commented on Apr 30, 2025

    @NiKrause
    Contributor

    This issue could be related. libp2p/js-libp2p#3015
    A limited circuit-relay connection to a peer is ending for various reasons (e.g. firewall problem, mobile network interruption while driving through country side, etc.) which might interrupt the replication process (interrupts the OrbitDB protocol stream or similar).

    In such case it is possible a db "crashes" and becomes inaccessible. In my opinion the replication of that db should be rolled back to a previous state. Not sure if I am experienced enough to provide a PR for that. (In case someone reads this and agrees)

  5. NiKrause commented on May 6, 2025

    @NiKrause
    Contributor
  6. haydenyoung commented on Aug 4, 2025

    @haydenyoung
    Member

    Please upgrade to OrbitDB v3. If the problem persists, please reopen this issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions