-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
[Usb Serial JTAG] [Deadlock] [Console Deinit] esp_vfs_usb_serial_jtag_use_nonblocking() causes deadlock (IDFGH-8520) #9974
Comments
My console Init code is copied from
But the comment confuses me. Shouldn't it be this code?
But regardless, it does not fix the issue. I still deadlock at the same place. edit: i think this is because linenoiseProbe() doesnt restore the O_NONBLOCK flag correctly
|
I've tried replacing
Logs:
I'm having a hard time trusting USB Serial JTAG.... 😔 It's quite hard to use without issues. The UART console works so easily, but Usb Serial JTAG is much more tricky, especially if you want to dynamically switch between console and Usb Host. Why dynamically switch? Under normal operation I need to use USB Host, but retaining access to the USB Serial Console when needed is extremely useful. |
Futhermore, from the docs:
I really think this should not be the default behavior. It is incredibly hard to debug a hanging program. It is greatly preferable to skip the bytes if the buffer is full. I am currently debugging with nothing attached to the USB port, so it should never hang I would think, but for some reason using |
I'm working on a ESP-IDF solution that uses new functions:
|
Pull Request: #9983 Please consider & feel free to modify. It has been tested on S3. |
Edit: Pull Request: #9983 now fixes this. This was due to linenoise thread forever holding the _readlock semaphore, which blocked
esp_vfs_usb_serial_jtag_use_nonblocking().
v4.4.2
ESP32-S3
Steps to reproduce.
Related Issue: #9964
Goal: To deinit the Usb Serial JTAG Console if there has been no user input after 3 seconds since boot, because we otherwise need to use the port for USB Midi Host.
Unfortunately it deadlocks at
_lock_acquire_recursive(&s_ctx.read_lock);
inesp_vfs_usb_serial_jtag_use_nonblocking()
. Hopefully I can explain it well.Relevant code:
https://github.com/espressif/esp-idf/blob/master/components/vfs/vfs_usb_serial_jtag.c
https://github.com/espressif/esp-idf/blob/master/components/driver/usb_serial_jtag.c
I've debugged it pretty far.
while(!should_stop) { char* line = linenoise(prompt); ....}
esp_console_repl.c
:Deinit Code:
Going deeper, here is the code of the function that deadlocks:
esp_vfs_usb_serial_jtag_use_nonblocking
This deadlock is not surprising, because I believe
s_ctx.read_lock
is currently still held by the linenoise() call!Call chain:
You can see that
usbjtag_rx_char_via_driver
blocks forever, so the read lock is never given back!I've yet to find a solution.
My Code
The text was updated successfully, but these errors were encountered: