-
Notifications
You must be signed in to change notification settings - Fork 9
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
UnhandledPromiseRejectionWarning #24
Comments
I just realized that this also happens in an example script. Using Node v14.8. On consecutive executions the the warning pops up sometimes, but sometimes not.
|
@mnemo70 Thank you for the report. I will solve this problem as soon as possible! |
@mnemo70 Unfortunately I cannot reproduce the error. Can you please log the error using const Vallox = require('../');
(async () => {
const client = new Vallox({ ip: '192.168.178.31', port: 80 })
try {
await client.setProfile(client.PROFILES.HOME)
} catch (error) {
console.log(error)
}
})() The IP address is correct? |
@danielbayerlein Yes, the IP is correct, of course. I have a Vallox ValloPlus 270 MV (type 3722) with software V2.0.2. The warning does not trigger on every execution, maybe it's only reported when the connection fails in which case the Promise is rejected. What happens when you run into the rejection in your test? I also have the problem that the API fails quite often in Node-RED with a "socket hang up" exception. But that would be another issue... This is the result of your script:
|
What happens is that the WebSocket sometimes throws the Error "socket hang up". This results in the Promise from _request() being rejected in ws.onerror, but the calls to _request() do not handle the rejection. For example, in fetchMetrics(), the call to _request() should be extended like this:
It's the same for the call in setValues():
This is the upper layer problem of correctly handling the Promise, but the underlying problem is with the WebSocket. On my machine, it's always the call to setValues() in setProfile() that generates a "socket hang up" error. setProfile() first calls fetchMetrics() which hasn't thrown an error yet, then calls setValues(). I can imagine that the Vallox unit needs some time to handle the closing of the first WebSocket before it can process the seconds connection. I'll analyze this further in the next days. |
I guess the gold standard would be to open the WebSocket connection only once and re-use it internally (or even allow it externally in the public API). This would relieve the Vallox unit from the costs of closing and re-opening the connection. The easier way would be to just retry the operation a few times with a short delay. I'll try to come up with some solution and submit a Pull Request. |
Hi, thanks for your API module. I'm trying to write Node-RED nodes around it and on the first call to setProfile() it works, but a second call then raises this warning on the Node-RED console:
I suspect that the calls to _request() in fetchMetrics() and setValues() trigger this warning or internal exceptions because I don't see any exception handling in there.
I'm using try/catch around the setProfile() call in my node, which should be okay. The catch does not get triggered.
Since I'm not an expert in Node.js, can you shed a light on this, please? Please excuse me if I'm totally wrong. :-)
Kind regards,
Thomas
The text was updated successfully, but these errors were encountered: