Skip to content
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

Paste in Web Workflow terminal often causes issues #7054

Closed
tyeth opened this issue Oct 14, 2022 · 7 comments
Closed

Paste in Web Workflow terminal often causes issues #7054

tyeth opened this issue Oct 14, 2022 · 7 comments

Comments

@tyeth
Copy link

tyeth commented Oct 14, 2022

CircuitPython version

8.1 latest git on equivalent of Adafruit Huzzah ESP32, but really a lilygo/ttgo t-sim7000g.

Observations

I'm just trying this board out and have been seeing this issue regularly while pasting in things to the web Serial Terminal, doesn't matter if using mDNS or IP to access, but comes up with this console error and there is no way to re-enable the websocket. Refreshing once doesn't resolve, but after 3times works (maybe websockets on device are not being closed correctly until another connection arrives and pool gets cleared). Other web workflow pages refresh fine.

The clearest example seems to be pasting in this line to the input box pin = machine.Pin(0, machine.Pin.IN, machine.Pin.PULL_UP) and then going with the cursor (mouse click) to add a 1 after pin, which somes before and sometimes after editing locks up the web terminal with the following error in console:
WebSocket connection to 'ws://192.168.0.39/cp/serial/' failed: Could not decode a text frame as UTF-8.
It seems to just happen a lot on paste, irrespective of what you do afterwards in the input box.

@tyeth tyeth added the bug label Oct 14, 2022
@dhalbert dhalbert added this to the 8.x.x milestone Oct 17, 2022
@DavePutz
Copy link
Collaborator

Verified that the problem exists on ESP32-S2 and ESP32-S3 with the latest build as well; but not on a PICO-W. The issue seems to be tied to overflows on the receiving ring buffer that are not being checked for in websocket_background().

@tannewt
Copy link
Member

tannewt commented Feb 27, 2023

@DavePutz are you working on a fix?

@DavePutz
Copy link
Collaborator

@tannewt Yes. I have seen that by increasing the size of _buf in supervisor/shared/web_workflow/websocket.c the issue can be avoided; at least until the size of _buf is exceeded again. This does not look like a great fix to me, so I am trying to see why the buffer is overflowing in the first place.

@tannewt
Copy link
Member

tannewt commented Feb 28, 2023

@DavePutz seems like we may not want to take bytes from the socket if the ringbuf is full.

@DavePutz
Copy link
Collaborator

DavePutz commented Mar 7, 2023

So, it looks like this issue is caused by the placement of RUN_BACKGROUND_TASKS in socketpool_socket_recv_into() for espressif boards. When web workflow is active; the code:

    while (ringbuf_num_empty(&_incoming_ringbuf) > 0 &&
           _read_next_payload_byte(&c)) {

in websocket_background() means that after the test for ringbuf_num_empty is done, calling _read_next_payload_byte() can eventually result in background calls, thus ending up calling websocket_background() again. The Pico W works because there is no call to RUN_BACKGROUND_TASKS in socketpool_socket_recv_into(). @tannewt ; is the RUN_BACKGROUND_TASKS necessary? I took it out (which fixed this issue) and other things seemed to run OK; but I'm not sure what side effects might be caused.

@tannewt
Copy link
Member

tannewt commented Mar 8, 2023

I'm not sure it is necessary. It might be an artifact of using blocking sockets during development. I'd suggest moving it to the bottom of the while loop so it only happens if we go around the loop again.

DavePutz added a commit to DavePutz/circuitpython that referenced this issue Mar 8, 2023
dhalbert added a commit that referenced this issue Mar 9, 2023
Fix for issue #7054 by avoiding recursive calls to websocket_background.
dhalbert pushed a commit to dhalbert/circuitpython that referenced this issue Mar 9, 2023
tannewt added a commit that referenced this issue Mar 9, 2023
8.0.x backport: Fix for issue #7054 by avoiding recursive calls to websocket_background.
@dhalbert
Copy link
Collaborator

dhalbert commented Apr 14, 2023

Fixed by #7694.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants