-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Is there a maximum script length? #25
Comments
Yes there is a default maximum size for 1 command (command, not entire script), defined here: If you use the thread_start/end commands there is a default maximum of 32768 characters and this buffer is supposed to grow until all RAM is used. But something could be wrong with this as well. I'll have to check... Maybe you can try changing one of these default buffer size and see if the problem solves? |
I increased the DEFAULT_COMMAND_LINE to 32768 for testing. It didn't seem to make a difference with respect to hanging. I have a strip of 540 LEDs and tried doing 54 evenly-spaced chasing lights - basically a string of
I wasn't able to get 54 chasers going, it hung and dropped the wifi connection. I was able to get 20 chasers going (the script is a bit under 500 characters) but I did see it freeze in the middle of execution and, again, drop the wifi connection. I wasn't sending anything to it, just letting it run. I'm not sure if this is a hardware limitation, like if I'm expecting the Raspberry Pi 3B to do too much or what. Still researching. |
More testing with 32768 characters - I got 40 chasers working, 50 consistently hangs. The 40 chaser script is 988 characters long.
I can consistently get it to hang on 54 chasers, an 1158 character script. The first time I send it, it seems to work fine. The second time, say with a different color, it will consistently hang the whole RPi.
Again, unclear if there's a hardware limitation or what. I'm not sure how to do much diagnosis or see if there are errors cropping up. I have |
I will take a look at it as soon as I have time, it must be some kind of buffer overflow I think... |
I've tried your code and it seems to work fine on my Raspberry Pi 3B. In the beginning there was a bit of lag on ssh but no total crash. You are running it as a service in the background right? What happens if you start it manually from ssh? Also: at the end after thread_stop; there needs to be an ENTER or the command will not be processed when the connection is closed. |
I haven't noticed a difference if it's run interactively or as a service, but I'll try again to validate. I do know I have not been sending any |
I added a '\n' and it didn't seem to make a difference. That said, I was able to get the above script to run once and then the second time I tried it using a different color - hang. I rebooted the Pi and tried again - I was able to run the long script twice and it hung on the third time. I saw this behavior both as a background service and interactive. I'm starting the service using When it hangs during interactive runs, it appears I don't get to the point where it says "client connected":
In the above scenario, I ran the long script first with red, then with green... and the third try I was going for blue but that's where you see Do you have a test script somewhere that you use to send TCP commands to your server? I could try my command string using your test script and see if maybe I'm doing something wrong in my client app's TCP communication. I mean, it should be straightforward, but who knows. |
Which Raspberry board / Raspbian version are you using? Maybe something changed recently? Can you try running the server directly on the Pi (attach keyboard and monitor) maybe it will print something you cannot see on ssh because at that point ssh is already dead. Command line option -d will also enable debugging output. This will print some things about what it is processing but not sure if it will help. |
I'm on a Raspberry Pi 3B (not 3B+). I can try running it locally but not with lights connected. My lights are mounted around my ceiling along with the power supply and Pi. I can't get cables up there. Unsure if that'd be much value. Will try the -d when I get a chance. |
It should not make a difference unless it is a power supply problem. The communication is one way so the program never knows how many leds are attached. |
I hooked up a keyboard and monitor locally and ran: sudo /usr/bin/ws2812svr -d -tcp 9999 I then ran my app and sent in the long script. A lot of text shot out and then when I tried to send the script again (this time with a different color), the hang occurred - or, at least, where I assume the hang would be, because the text stopped scrolling and the new script didn't take effect. The tail of the log, including my attempt to stop and start the server again, looks like this:
On that last
After about 10 minutes of looking at netstat data, I tried running the server again and port 9999 was available again. It came up with
However, when I tried to connect to port 9999 via my app, my app hung on the connect command - I never could connect again. I exited the server with Ctrl+C and did
And that's where it hung. I had to hard power off/on to get it to reboot. Now, here's where it gets weird. I decided to step through the connect/send/disconnect in my app to see where things get hung up... and when I was stepping through I couldn't reproduce the issue. I now find that if I introduce a half-second of sleep time between connecting to the server and sending the new script that things pretty consistently work. While I can't prove it at the moment, it feels as though the thread from the previous script needs time to stop before the new script starts with a new thread; and the sleep time between the connect and the send is giving it just enough time to be properly handled. Or maybe I had connected but the server wasn't quite ready to receive everything? I dunno. Regardless, here's what it looks like in C#: socket.Connect(endpoint);
// Adding this sleep time seems to be the magic.
Thread.Sleep(500);
socket.Send(msg, 0, msg.Length, SocketFlags.None);
socket.Shutdown(SocketShutdown.Both);
socket.Close(); I'll keep messing with it, but with that sleep time on my side I'm getting pretty consistent success, at least when running with the keyboard/monitor and disconnected from the lights. I'm going to hook it all back up for real and try some more. |
Verified - I've been messing with this for an hour, sending script after script at it, and if I have the sleep in place it seems to work without fail. I'm not sure what the minimum sleep value needs to be, but I've slowly been reducing it and I'm down to 200ms without any issue, which for my purposes is plenty enough "real time script change." |
When you close the connection the server needs a liltle bit of time to go back to listen mode. Seems like it can't handle a new connection request while switching from connected back to listen mode. Strange though because Raspbian OS should all take care of this and not crash the network interfaces... |
I don't know enough about how it gets handled at the OS level, but to be clear, I'm not hammering it with connect/disconnect rapid fire, is more... Connect, send, disconnect, watch the lights for a few seconds. It's the subsequent connect and send that gets stuck, so it's more like something needs time between connect and receive. Many of my scripts have the thread start/end; any chance there's something hanging during the thread end? The thread ends on connect, right? |
Yes it could be the program hangs somewhere but this should not mess up you network/ssh should still continue to work. |
Inserting 'ipv6.disable=1' in '/boot/cmdline.txt' solved the problem for me. |
I've got the ws2812svr starting at Raspberry Pi / Raspbian startup via an /etc/init.d script like this:
I have a web app connecting to port 9999 and sending scripts to the lights which include the setup, like:
setup 1,540,3,0,64;init;thread_start;fill 1,ff0000;render;thread_end;
I am able to send any number of short scripts like this with no issue. I can send, like, 10 in a row, no issues.
However, I did notice that if I send a script that exceeds around 1000 characters the whole Raspberry Pi crashes, or at least it hangs so hard it won't respond to any network requests anymore including SSH. I end up having to hard reset it by power cycling.
I thought it was #20 but since I can send the setup any number of times with smaller scripts, I figured it may be that I'm running into something else like a buffer overflow or something else.
Possibly related, possibly a separate thing... when I was trying to set the server up like this...
/usr/bin/ws2812svr -i "setup 1,540,3,0,64;init;" -tcp 9999 &
...I was only able to send a single script (which didn't include setup/init) before my lights stopped responding. I wasn't sure how to determine what was going on. I do know that when I removed the inline setup and went back to sending setup/init with the scripts things started working predictably again. Except, of course, in the case I had a longer script.
The text was updated successfully, but these errors were encountered: