question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

node.getEndpoint call fails sometimes

See original GitHub issue

This appears to be a race condition as it only manifests itself sometimes.

When you call node.getEndpoint, it will throw an exception at some occasions. In the WS server we call this right after “value added” to determine the CC version of the CC belonging to the value. 99% of the times this is OK but sometimes this fails, I believe this happens when interview is still busy ?

Code in the WS server where the exception throws: https://github.com/zwave-js/zwave-js-server/blob/master/src/lib/forward.ts#L142

Capture of the error:

10:52:59.106 DRIVER   Node 28, Endpoint undefined: Trying to access endpoint instance before Multi Channel interview
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(). The promise rejected with the reason:
TypeError: Cannot read property 'getCCVersion' of undefined
    at ZWaveNode.<anonymous> (/usr/lib/node_modules/@zwave-js/server/dist/lib/forward.js:107:56)
    at ZWaveNode.emit (events.js:315:20)
    at ZWaveNode.EventEmitter.emit (domain.js:467:12)
    at ZWaveNode.translateValueEvent (/usr/lib/node_modules/@zwave-js/server/node_modules/zwave-js/src/lib/node/Node.ts:346:8)
    at ValueDB.emit (events.js:315:20)
    at ValueDB.EventEmitter.emit (domain.js:467:12)
    at ValueDB.setValue (/usr/lib/node_modules/@zwave-js/server/node_modules/@zwave-js/core/src/values/ValueDB.ts:224:10)
    at new ConfigurationCCReport (/usr/lib/node_modules/@zwave-js/server/node_modules/zwave-js/src/lib/commandclass/ConfigurationCC.ts:916:22)
    at new CommandClass (/usr/lib/node_modules/@zwave-js/server/node_modules/zwave-js/src/lib/commandclass/CommandClass.ts:108:13)
    at new ConfigurationCC (/usr/lib/node_modules/@zwave-js/server/node_modules/zwave-js/src/lib/commandclass/ConfigurationCC.ts:484:3)

I can simply wrap the call in a try…except or first check if the endpoint is defined but that doesn’t really fix the issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
marcelveldtcommented, Jan 26, 2021

Thanks for all the help and insight again. We’re going the safer route and only request all these metadata after the node is ready.

0reactions
AlCalzonecommented, Jan 26, 2021

Yeah, the problem here is that the node is sending a multi channel encapsulated command (from an endpoint), which zwave-js emits as a value event, so it doesn’t get missed.

However at that point the Multi Channel CC interview was not completed yet, so zwave-js does not have any information about endpoints yet. You’re trying to read the CC version of that endpoint which is also not known yet at that point, since the endpoint interview happens after the Multi Channel CC interview of the node.

Long story short: The type declarations reflect the error too. grafik

Workaround (I assume your TS version is high enough to support optional chaining):

          args.ccVersion =
-            node.getEndpoint(args.endpoint).getCCVersion(args.commandClass) ||
-            node.getEndpoint(0).getCCVersion(args.commandClass);
+            node.getEndpoint(args.endpoint)?.getCCVersion(args.commandClass) ||
+            node.getCCVersion(args.commandClass);

getEndpoint(0) is also a no-op, it just returns the node instance itself.

I’m not sure how you use these versions, but keep in mind that falling back to the node version in this case can leave you with outdated information after the interview is completed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Express router GET endpoint gives Not Found error
My request. GET http://localhost:3000/dev/v1/abc/48/def. I'm having an issue with the first GET endpoint not reaching and getting 404 ...
Read more >
Understanding Axios GET requests - LogRocket Blog
Learn how to make GET requests in Axios with query parameters and API keys, plus concurrent and HEAD requests and error handling.
Read more >
Fetch API – How to Make a GET Request and POST Request ...
As a result, you will not be able to use it in a Node.js environment (unless you install a special module). How to...
Read more >
Cassandra troubleshooting guide - Site24x7
If only a particular query consistently fails, you can use nodetool getendpoints to get all the nodes that own a particular partition key....
Read more >
Building requests | Postman Learning Center
To test the https://postman-echo.com/get endpoint, leave the GET method selected and select Send. The same location (sometimes called ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found