Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection interruption terminates the whole process, doesn't allow to be try/caught #34

Open
rik-iso opened this issue Jul 18, 2024 · 1 comment

Comments

@rik-iso
Copy link

rik-iso commented Jul 18, 2024

I'm trying to make the code resilient to a Aurora RDS failover (which interrupts the connection to the master). I'm wrapping my await service.subscribe(plugin, REPLICATION_SLOT_NAME) in a try/catch, but when I fail over the whole process just ends:

/Users/rik/iso/Code/graph/node_modules/.pnpm/[email protected]/node_modules/eventemitter2/lib/eventemitter2.js:1053
        throw arguments[1]; // Unhandled 'error' event
        ^

Error: Connection terminated unexpectedly
    at Connection.<anonymous> (/Users/rik/iso/Code/graph/node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js:132:73)
    at Object.onceWrapper (node:events:628:28)
    at Connection.emit (node:events:514:28)
    at Connection.emit (node:domain:489:12)
    at Socket.<anonymous> (/Users/rik/iso/Code/graph/node_modules/.pnpm/[email protected]/node_modules/pg/lib/connection.js:63:12)
    at Socket.emit (node:events:514:28)
    at Socket.emit (node:domain:489:12)
    at TCP.<anonymous> (node:net:323:12)

Node.js v18.17.1

This occurs if I use the example code in the README too.

@rik-iso rik-iso changed the title Crash terminates the whole process Connection interruption terminates the whole process, doesn't allow to be try/caught Jul 18, 2024
@rik-iso
Copy link
Author

rik-iso commented Jul 18, 2024

Ok looks like adding

  service.on('error', (er) => {
    console.log(er)
  })

i.e. handling the error somehow fixes it. I guess this is an eventemitter2 thing. Would be worth documenting as the example in the README doesn't work to retry like it implies it does.

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

No branches or pull requests

1 participant