Bug 1299 - Deadlock when USB device is disconnected during acquisition and acquisition start is requested
Summary: Deadlock when USB device is disconnected during acquisition and acquisition s...
Status: CONFIRMED
Alias: None
Product: libsigrok
Classification: Unclassified
Component: Other (show other bugs)
Version: unreleased development snapshot
Hardware: All All
: Normal normal
Target Milestone: ---
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-09 23:20 CEST by Soeren Apel
Modified: 2021-01-27 11:42 CET (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Soeren Apel 2018-10-09 23:20:34 CEST
Reproducible by LeoNerd, Peetz0r and myself.

sr: [00:25.164210] fx2lafw: receive_transfer(): status LIBUSB_SUCCESS / LIBUSB_TRANSFER_COMPLETED received 512 bytes.
sr: [00:25.164310] session: bus: Received SR_DF_LOGIC packet (512 bytes, unitsize = 1).
sr: [00:25.182720] fx2lafw: receive_transfer(): status LIBUSB_TRANSFER_NO_DEVICE received 0 bytes.
sr: [00:25.183000] std: fx2lafw: Sending SR_DF_END packet.
sr: [00:25.183075] session: bus: Received SR_DF_END packet.
sr: [00:25.183176] usb: usb_source_finalize
sr: [00:25.183264] session: Stopped.
[Thread 0xa9ef6b40 (LWP 3660) exited]

...at this point, PV is still responsive but when clicking 'Run' again, it freezes:

[New Thread 0xa9ef6b40 (LWP 3689)]
sr: [00:34.985572] hwdriver: sr_config_get(): key 30000 (samplerate) sdi 0x8842968 cg NULL -> uint64 20000
sr: [00:34.985684] session: Creating our own main context.
sr: [00:34.985744] session: Starting.
sr: [00:34.985786] hwdriver: fx2lafw: Starting acquisition.
sr: [00:34.985853] fx2lafw: submitting transfer: 0
sr: [00:34.985920] fx2lafw: Failed to submit transfer: LIBUSB_ERROR_NO_DEVICE.
sr: [00:34.985964] fx2lafw: GPIF delay = 1499, clocksource = 30MHz.
sr: [00:34.986007] fx2lafw: Unable to send start command: LIBUSB_ERROR_NO_DEVICE.
sr: [00:34.986036] session: Could not start fx2lafw device usb/3-3 acquisition.
sr: [00:34.986069] hwdriver: fx2lafw: Stopping acquisition.
sr: [00:34.986103] usb: usb_source_finalize

...frozen now. CTRL-C gives:

Thread 17 (Thread 0xa9ef6b40 (LWP 3689)):
#0  0xb7fdb9a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1  0xb68d1647 in syscall () from /lib/libc.so.6
#2  0xb7c8b2f1 in g_mutex_lock_slowpath () from /usr/lib/libglib-2.0.so.0
#3  0xb7e0f06f in session_source_attach (session=session@entry=0x89eb9f8, source=source@entry=0xae506bc8) at src/session.c:661
#4  0xb7e0f314 in stop_check_later (session=session@entry=0x89eb9f8) at src/session.c:723
#5  0xb7e106ce in stop_check_later (session=0x89eb9f8) at src/session.c:1450
#6  sr_session_source_destroyed (session=0x89eb9f8, key=0x8614660, source=0xae501fa8) at src/session.c:1449
#7  0xb7e2c998 in usb_source_finalize (source=0xae501fa8) at src/usb.c:169
#8  0xb7c449a6 in g_source_unref_internal () from /usr/lib/libglib-2.0.so.0
#9  0xb7c44c71 in g_source_iter_next () from /usr/lib/libglib-2.0.so.0
#10 0xb7c450a0 in g_main_context_unref () from /usr/lib/libglib-2.0.so.0
#11 0xb7e0f00f in unset_main_context (session=session@entry=0x89eb9f8) at src/session.c:642
#12 0xb7e0fbbc in sr_session_start (session=0x89eb9f8) at src/session.c:839
#13 0xb7e9a63b in sigrok::Session::start (this=0x89d0938) at bindings/cxx/classes.cpp:984
#14 0x082e2e68 in pv::devices::Device::start (this=0x8833e28) at /home/abraxa/repositories/sigrok/pulseview/pv/devices/device.cpp:75
#15 0x0826ecf4 in pv::Session::sample_thread_proc(std::function<void (QString)>) (this=0x89147d4, error_handler=...) at /home/abraxa/repositories/sigrok/pulseview/pv/session.cpp:970

session.c:661 is "g_mutex_lock(&session->main_mutex);" and since this is apparently a deadlock, we're stuck.
Comment 1 Miguel Reis 2021-01-27 11:32:42 CET
2 Years later and this still hasnt been fixed. I have to kill and restart pulseview everytime this happens, which happens to be after 2 or 3 readings.
Comment 2 Soeren Apel 2021-01-27 11:42:19 CET
It's unfortunate that this happens to you and I of course wish that this would not happen. But it's also a pretty rare thing to happen for other people, so priority is rather low - especially considering the effort needed to create a solution that works across all platforms.

As this is free software created by unpaid volunteers in their spare time, you're of course also welcome to look into this issue and provide a fix that benefits people like yourself.