Skip to content

Websocket connection failure via pool results in uncaught exception #130

@chmac

Description

@chmac

Steps to reproduce

  • Create a simple pool
  • Add a non existent relay
  • Connect
  • Note the nostr.esm.js:574 Uncaught (in promise) undefined error

I think the problem is that there's no await here:

nostr-tools/pool.ts

Lines 56 to 59 in f43d23d

relays.forEach(async relay => {
let r = await this.ensureRelay(relay)
if (!r) return
let s = r.sub(filters, modifiedOpts)

Well, to be clearer, the async function that's invoked by the .forEach() is not awaited anywhere. It's just started. Maybe the solution would be to change .forEach() to a .map() and wrap the output in a Promise.all()? But, that would mean that failure to connect to any single relay would crash the whole pool. I guess that's probably not what we want.

I've always found it challenging to handle errors on one of the relays in a group. I suppose ideally the errors would be made available to the client of the API in some way. But the current API wouldn't support anything like that.

Another approach would be to check if all relays have failed, and if they have, then fail the whole process. Perhaps instead of a Promise.all() then a Promise.race() would work for that...

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