Skip to content

fix(rtlsdr): probe_with_timeout exclusive USB fix + FFT perf reduction - #6

Merged
jochenhammes merged 2 commits into
mainfrom
fix/rtlsdr-probe-fft-perf
Nov 3, 2026
Merged

jochenhammes merged 2 commits into
mainfrom
fix/rtlsdr-probe-fft-perf

Conversation

@jochenhammes

Copy link
Copy Markdown
Owner

Summary

  • RTL-SDR double-open bug: probe_with_timeout opened the device via soapy.source(), which holds exclusive USB access via librtlsdr. The immediately-following build_source() call then tried to open the same device again, corrupting the USB state and producing a flood of rtlsdr_demod_write_reg/-read_reg failures (errno -4 / LIBUSB_ERROR_NO_DEVICE) and eventually crashing all transfers (cb transfer status: 5, canceling...).

    Fix: use SoapySDR.Device.enumerate() in probe_with_timeout instead. enumerate() confirms the device is present without opening it. Falls back to the soapy.source approach when python3-soapysdr is not installed.

    Reproducer: web-trx auto-restore (which calls probe_with_timeout at startup) followed by build_source in the same connect() call — the librtlsdr handle from the probe was not yet released by Python's GC when build_source ran.

  • FFT rate reduction: On a 4-thread i5-6300U running RTL-SDR + FT8 in web-trx, the uvicorn process peaked at ~120% CPU, making FT8 reception choppy. Reducing FFT_COMPUTE_RATE_HZ from 30 to 15 Hz cuts GNU Radio resampler and FFT work roughly in half. The waterfall still scrolls at 15 rows/s, sufficient for all supported modes including FT8 (15 s slots). SPECTRUM_POLL_HZ aligned to match.

Test plan

  • Connect RTL-SDR in web-trx: verify no rtlsdr_demod_write_reg failed errors in log after connecting
  • Restart web-trx with RTL-SDR saved: verify auto-restore succeeds without double-open
  • Verify waterfall scrolls smoothly at 15 rows/s for FM, SSB, FT8
  • Verify python3-soapysdr fallback path still works if SoapySDR import fails

🤖 Generated with Claude Code

jochenhammes and others added 2 commits November 3, 2026 19:33
soapy.source() holds exclusive USB access via librtlsdr. Opening the
device in probe_with_timeout and then immediately in build_source
caused the second open to corrupt the first's USB state, producing
a flood of rtlsdr_demod_write_reg/-read_reg failures with errno -4
(LIBUSB_ERROR_NO_DEVICE) and eventually crashing the transfer loop
("cb transfer status: 5, canceling...").

Fix: use SoapySDR.Device.enumerate() for the probe check instead.
enumerate() confirms the device is present without opening it, so
build_source gets a clean handle. Falls back to the soapy.source
approach when python3-soapysdr is not installed.

Reproducer: web-trx auto-restore (which calls probe_with_timeout on
startup) followed immediately by build_source in the same connect()
call -- the librtlsdr handle from the probe was not yet released by
Python's GC when build_source ran.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
FFT_COMPUTE_RATE_HZ: 30 -> 15 Hz
SPECTRUM_POLL_HZ:    25 -> 15 Hz

On a 4-thread i5-6300U running RTL-SDR + FT8 in web-trx, the uvicorn
process peaked at ~120% CPU, making FT8 reception choppy. Halving the
FFT compute rate cuts the GNU Radio resampler and FFT work roughly in
half. The waterfall still scrolls at 15 rows/s, which is more than
enough for all supported modes including FT8 (15 s slots).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jochenhammes
jochenhammes merged commit d5befc1 into main Nov 3, 2026
3 checks passed
@jochenhammes
jochenhammes deleted the fix/rtlsdr-probe-fft-perf branch November 3, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant