ThorbenJ / nrc-elasticsearch-nodes

A set of Node-RED contributed (NRC) nodes for Elasticsearch
MIT License
1 stars 0 forks source link

Wrong credentials or url crash node red instance #5

Closed salarelv closed 9 months ago

salarelv commented 10 months ago

When I insert wrong credentials my node red docker container crashes. I have to manually restart it

node-red_1 | Root causes: node-red_1 | security_exception: unable to authenticate with provided credentials and anonymous access is not allowed for this request node-red_1 | at SniffingTransport.request (/data/node_modules/@elastic/transport/lib/Transport.js:479:27) node-red_1 | at processTicksAndRejections (node:internal/process/task_queues:96:5) node-red_1 | at async Client.SearchApi [as search] (/data/node_modules/@elastic/elasticsearch/lib/api/api/search.js:66:12) node-red_1 | at async Helpers.scrollSearch (/data/node_modules/@elastic/elasticsearch/lib/helpers.js:115:24) node-red_1 | at async Search._inputCallback (/data/node_modules/nrc-elasticsearch-nodes/doc/search.js:63:38)

ThorbenJ commented 9 months ago

Hi.

This was tricky to recreate, however looks like the result of uncaught errors which were difficult to catch with the nest of Promises and async functions.

Now in 0.3.16 the connection node tried to get the cluster info, and only then creates a .client() method for other nodes to use. Until then a dummy .client() is provided that will emit a "Not connected" error and return undefined.

The point being: any "Tail" nodes will likely fail on their first attempt, because they will immediately try to search before the connection node has setup the connection. If the connection setup is valid, the Tail node will succeed on its second scheduled attempt, as by then then the connection node setup should be complete.

Oh the fun of the async world. Maybe Node-red connection nodes have a way to signal they are not ready, such was not apparent to me.

Ultimately incorrect connection info should no long result in an uncaught error.