Repository navigation
Conversation
Serial_2_Socket::write runs in Marlin's loop task. On each newline it processed the line there, so dispatching to the websocket and other clients ran in Marlin's task. Sending to a websocket client that has stopped reading waits up to about 15 s (WiFiClient write retries plus the WebSockets TCP timeout), long enough to trip Marlin's task watchdog. write() and flush() now put each message on a queue (dropping it if the queue is full), and handle(), in the ESP3D task, processes the queue. WebSocket_Server sends to each client in turn and disconnects a client whose send fails, so it can't stall later sends.
Owner
|
Thank you, Yes the processing should be in ESP3DLib task on core 0 - interresting that I never got such issue - but the WDT is handled differently in my fork as far I can remember - I will review it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Serial_2_Socket::write()is called by Marlin, from Marlin's loop task. On each newline (and when the buffer filled or timed out) it calledflush(), which ranesp3d_commands.process()on the line in that task. So dispatching to the websocket and other clients ran in Marlin's task, andWebSocket_Server::writeBytes()callsbroadcastBIN()when its own buffer fills.Sending to a websocket client that has stopped reading blocks. With a full TCP send buffer,
WiFiClient::write()waits up to 10 × 1 s inselect(), andWebSockets::write()keeps retrying for up toWEBSOCKETS_TCP_TIMEOUT(5 s). Marlin's loop task stops for that time. Marlin watches that task with a 4 s task watchdog (USE_WATCHDOG, MarlinFirmware/Marlin#28725), so the board resets. A web UI tab left open on a phone that has gone to sleep, or a client that dropped off the WiFi, can do this during a print.This PR keeps the processing in the ESP3D task:
write()andflush()turn the TX buffer into a message as before, but put it on a FreeRTOS queue (S2S_TXQUEUESIZE, 32) instead of processing it. If the queue is full, the message is dropped.handle(), called from the ESP3D task, processes the queued messages afterhandle_flush().WebSocket_Server::flushTXbuffer()sends to each connected client withsendBIN()instead ofbroadcastBIN(), and disconnects a client whose send fails, so it can't stall every later send.Testing
MKS TinyBee, Marlin
bugfix-2.1.xwith arduino-esp32 3.0.4 (pioarduino 51.03.04),ESP3D_WIFISUPPORT,WEBSUPPORT,USE_WATCHDOG, station mode. A script sentM503to/command?cmd=every 0.3 s andM118over USB serial every 0.5 s. A test websocket client (webui-v3, port 81) completed the handshake and then never read.M503flood, 60 sloopTask) 7.7 s inM118answered in 0.06 s or less