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

Node-RED crashes when Postgres terminates connection unexpectedly due to out of memory error #97

Open
marcus-clements opened this issue Jan 9, 2025 · 8 comments · Fixed by #101
Labels
help wanted Extra attention is needed

Comments

@marcus-clements
Copy link

This looks related to #50

Node-RED v14.2
node.js v22.11.0

I am executing a query that occasionally causes an out of memory error in Postgres. This throws an uncaught exception which crashes Node-RED

8 Jan 16:29:16 - [error] [postgresql:Foo Query] error: out of memory
8 Jan 16:29:16 - [red] Uncaught Exception:
8 Jan 16:29:16 - [error] Error: Connection terminated unexpectedly
    at Connection.<anonymous> (/data/node_modules/pg/lib/client.js:131:73)
    at Object.onceWrapper (node:events:632:28)
    at Connection.emit (node:events:518:28)
    at Connection.emit (node:domain:489:12)
    at Socket.<anonymous> (/data/node_modules/pg/lib/connection.js:62:12)
    at Socket.emit (node:events:530:35)
    at Socket.emit (node:domain:489:12)
    at TCP.<anonymous> (node:net:343:12)
@Alkarex
Copy link
Member

Alkarex commented Mar 20, 2025

Sorry for the delay. I will try to have a look to see if we can add more catches.
Help or PR welcome

@Alkarex Alkarex added the help wanted Extra attention is needed label Mar 20, 2025
Alkarex added a commit that referenced this issue Mar 21, 2025
@Alkarex
Copy link
Member

Alkarex commented Mar 21, 2025

If you are still around, would you be able to test this little patch?
#101

@marcus-clements
Copy link
Author

I built our docker container from the commit for that patch and yes it works :)

I tested by causing the postgres instance to run out of memory with an infinite loop.
In 0.14.2 node-RED dies with the reported exception
Using commit 336461e I get an error message in the console but node-RED keeps running
[error] [postgreSQLConfig:docker timescaledb connection] Connection terminated unexpectedly

@Alkarex
Copy link
Member

Alkarex commented Mar 22, 2025

Excellent, thanks for the quick feedback @marcus-clements 👍🏻

@Alkarex
Copy link
Member

Alkarex commented Mar 22, 2025

@marcus-clements
Copy link
Author

marcus-clements commented Mar 31, 2025

@Alkarex Unfortunately this error has occurred again in v0.15.1, but with a different line number in pg/lib/client.js

I am experimenting with connection pool settings.

The change that causes this error to not be handled again seems to be that I added an Application Name in the Connection pool settings and set the idle timeout to 10s.

31 Mar 13:48:17 - [red] Uncaught Exception:
31 Mar 13:48:17 - [error] Error: Connection terminated unexpectedly
    at Connection.<anonymous> (/data/node_modules/pg/lib/client.js:136:73)
    at Object.onceWrapper (node:events:638:28)
    at Connection.emit (node:events:524:28)
    at Connection.emit (node:domain:489:12)
    at Socket.<anonymous> (/data/node_modules/pg/lib/connection.js:62:12)
    at Socket.emit (node:events:536:35)
    at Socket.emit (node:domain:489:12)
    at TCP.<anonymous> (node:net:351:12)

Is there some way to configure Node-RED to give the call stack so I can help you add further catches?

@marcus-clements
Copy link
Author

@Alkarex do you want to reopen this issue or should I create a new one?

@Alkarex Alkarex reopened this Apr 2, 2025
@Alkarex
Copy link
Member

Alkarex commented Apr 2, 2025

Let's reopen here. I do not know the answer to your question. Additional help welcome. I will try to find time to look at it but I am swamped until at least the weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants