Open virgin09 opened 1 day ago
I've noticed identical issues but never realized it might be linked to node v18. I tried tracking it down but never got any further than noticing the TTS mp3 files were ok but the http server simply didn't respond sometimes. I did update all dependencies that I could update without breaking the http api function. I don't have the skills to hunt further but will monitor this thread to help as much as I can.
In my case it’s definitely NOT linked to node v18. It’s solely a node v20 issue.
I think this is related to this global change in Node 20:
https://github.com/nodejs/node/pull/43522
The Sonos players probably doesn't like keep-alive, and might not properly respond with a Connection: close. The http api will maintain connections and try to send new requests over the old socket and probably confusing the player.
Since this only affects requests that happen within 30-90 seconds (not sure what the default timeout is), this might appear random.
I'll see if I can reproduce it, I haven't run this project under newer Node.js versions in a long time.
@jishi this sounds like a good error diagnosis. Please let me know what tests I should conduct in order to narrow down the problem. I’ll find this API extremely helpful!
@jishi Greetings from Germany. As I am not a javascript resp. programmer professional I have been using ChatGPT for help. Here is what KI suggests:
The developer's response provides an insightful explanation of the issue you're experiencing with the node-sonos-http-api under Node.js 20. Here's a breakdown:
Key Points in the Response Node.js 20 Change:
The issue is likely related to the global change in Node.js 20 introduced in the PR #43522, which modified how HTTP connections are handled, particularly with persistent (keep-alive) connections. Sonos Player Behavior:
Sonos players may not handle persistent HTTP connections (keep-alive) correctly. If the player does not properly close the connection (Connection: close header), the node-sonos-http-api attempts to reuse the connection for subsequent requests. This reuse could confuse the player and lead to errors like "No system has yet been discovered." Randomness of the Issue:
The problem might only occur when requests happen within the time frame that a connection remains open (30–90 seconds, depending on the default keep-alive timeout). This makes the issue seem random and harder to reproduce. Potential Solutions Disable Keep-Alive in node-sonos-http-api:
Modify the node-sonos-http-api code to ensure that all HTTP requests include a Connection: close header. This forces each request to use a new connection, avoiding potential conflicts with keep-alive. Example (in the API code):
javascript Code kopieren const options = { method: 'GET', headers: { 'Connection': 'close' } }; Rollback to an Older Node.js Version:
Temporarily downgrade to Node.js 18 or a version before Node.js 20 to see if the problem disappears. This would confirm that the keep-alive change is the root cause. Test with Updated Dependencies:
Ensure all dependencies in node-sonos-http-api are updated. Older libraries might not handle newer Node.js behaviors correctly. Adjust Node.js HTTP Agent Settings:
Use a custom HTTP agent to override default keep-alive behavior globally for node-sonos-http-api. Example: javascript Code kopieren const http = require('http');
const agent = new http.Agent({ keepAlive: false }); const options = { agent: agent }; Next Steps Test the suggestions provided to identify the most effective solution. Communicate with the developer if you find a consistent way to reproduce the issue under Node.js 20. Monitor the developer's progress on debugging and fixing this compatibility issue. This issue highlights the need to carefully manage dependencies and their compatibility when upgrading Node.js versions.
Does this help in any respect?
@virgin09 It's mostly a repetition of what I stated and the potential remedies I was thinking of 😄. But I need some reproducable error so I can validate a fix.
I'm trying to run it using v20.11.0 but I'm not seeing the same behavior. I also run MacOS here, which might affect things.
Could you please state exact 20 version you are running, and which OS/Arch (like, Linux amd64 or arm64 or if it's windows).
Thanks for your quick response. I am using node.js 20.18.1. The os is PRETTY_NAME="Debian GNU/Linux 12 (bookworm)" NAME="Debian GNU/Linux" VERSION_ID="12" VERSION="12 (bookworm)" VERSION_CODENAME=bookworm ID=debian
If you need further information, let me know. Also, if you want me to test anything, I am willing to help.
Up to node.js 18 the API worked wonderful. I am many using it with automated announcements from a JavaScript.
I am very sure that there is a connection between the malfunction of the API and node.js 20. As I am running my installation under Orcacle VirtualBox I can switch back and forth between the node.js versions 18 and 20.
Since node.js 20 I am receiving error messages „error=socket hang up“. They some repeatingly in a random manner. I was unable to identify the reason and source. I have been running many test, announcements/ text too long?, wrong strings?, too fast after one another announcement? Alle the tests ended nowhere. Randomly the announcements go thru sometimes after the third time, sometimes the first. But many times comes the socket hand up.
I also tried to start from a browser like chrome. As a result the browser notifies me „no connection to the server“. And - despite - it would play the announcement. Then, I get the same error message and it would not play. And the, sometimes, after the second call it works.
I am kind of desperate.
Has anyone experienced the same issue? How can I solve this problem? What can I test?