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

Unhandled promise rejection during reconnect #22

Closed
Ingramz opened this issue Jul 8, 2019 · 2 comments · Fixed by #23
Closed

Unhandled promise rejection during reconnect #22

Ingramz opened this issue Jul 8, 2019 · 2 comments · Fixed by #23
Labels
bug Something isn't working

Comments

@Ingramz
Copy link

Ingramz commented Jul 8, 2019

I'm getting unnecessary console spam from unsuccessful reconnect attempts that seem to be caused by the rejection on this line.

To cause temporary interruptions I used the following SQL. For the grant/revoke to work, the user which connection is being interrupted must not be a superuser. This is probably not the only way to cause an interruption, it could be also at the network level or by temporarily shutting down the database. Setting retryTimeout to a null value is useful as well.

-- Revoke new connections for non-superusers
REVOKE CONNECT ON DATABASE mydatabase FROM public;
-- Terminate currently active connections for a specific non-superuser 'myuser'
SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND usename = 'myuser';
-- Some time later restore ability to reconnect
GRANT CONNECT ON DATABASE mydatabase TO public;

I couldn't really understand in which state end is called in relation to the try/catch block where this code is placed, so I am unsure what the supposed fix should be.

Here's what I'm getting in console:

(node:14040) UnhandledPromiseRejectionWarning: Error: Connection ended.
    at Client.<anonymous> (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg-listen\dist\index.js:89:93)
    at Object.onceWrapper (events.js:286:20)
    at Client.emit (events.js:198:13)
    at process.nextTick (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg\lib\client.js:256:12)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:14040) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14040) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:14040) UnhandledPromiseRejectionWarning: Error: Connection ended.
    at Client.<anonymous> (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg-listen\dist\index.js:89:93)
    at Object.onceWrapper (events.js:286:20)
    at Client.emit (events.js:198:13)
    at process.nextTick (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg\lib\client.js:256:12)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:14040) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:14040) UnhandledPromiseRejectionWarning: Error: Connection ended.
    at Client.<anonymous> (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg-listen\dist\index.js:89:93)
    at Object.onceWrapper (events.js:286:20)
    at Client.emit (events.js:198:13)
    at process.nextTick (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg\lib\client.js:256:12)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:14040) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:14040) UnhandledPromiseRejectionWarning: Error: Connection ended.
    at Client.<anonymous> (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg-listen\dist\index.js:89:93)
    at Object.onceWrapper (events.js:286:20)
    at Client.emit (events.js:198:13)
    at process.nextTick (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg\lib\client.js:256:12)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:14040) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:14040) UnhandledPromiseRejectionWarning: Error: Connection ended.
    at Client.<anonymous> (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg-listen\dist\index.js:89:93)
    at Object.onceWrapper (events.js:286:20)
    at Client.emit (events.js:198:13)
    at process.nextTick (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg\lib\client.js:256:12)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:14040) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)
(node:14040) UnhandledPromiseRejectionWarning: Error: Connection ended.
    at Client.<anonymous> (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg-listen\dist\index.js:89:93)
    at Object.onceWrapper (events.js:286:20)
    at Client.emit (events.js:198:13)
    at process.nextTick (C:\Users\Indrek\Desktop\node-indexer\node_modules\pg\lib\client.js:256:12)
    at process._tickCallback (internal/process/next_tick.js:61:11)
...repeat...
@andywer
Copy link
Owner

andywer commented Jul 8, 2019

Hey @Ingramz!

Thanks for reporting. Yeah, the code is not exactly a beauty, I have to admit.
Anyhow, I might have a fix for the issue, haven't tested it yet, though.

Can you npm i [email protected] and see if it fixes the issue?

The fix can be found on this branch: bugfix/22-unhandled-rejection

Basically I just replaced two consecutive await that refer to very tightly coupled promises with one await Promise.all() handling both of them, so the second promise is assigned a rejection handler right away and not just after the first promise succeeded.

@andywer andywer added the bug Something isn't working label Jul 8, 2019
@Ingramz
Copy link
Author

Ingramz commented Jul 8, 2019

@andywer thank you for reacting so quickly ⚡️. I can confirm that this change has indeed solved it my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants