Repository navigation
fix(rtlsdr): probe_with_timeout exclusive USB fix + FFT perf reduction - #6
Merged
Merged
Conversation
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>
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.
Summary
RTL-SDR double-open bug:
probe_with_timeoutopened the device viasoapy.source(), which holds exclusive USB access via librtlsdr. The immediately-followingbuild_source()call then tried to open the same device again, corrupting the USB state and producing a flood ofrtlsdr_demod_write_reg/-read_regfailures (errno -4 / LIBUSB_ERROR_NO_DEVICE) and eventually crashing all transfers (cb transfer status: 5, canceling...).Fix: use
SoapySDR.Device.enumerate()inprobe_with_timeoutinstead. enumerate() confirms the device is present without opening it. Falls back to thesoapy.sourceapproach whenpython3-soapysdris not installed.Reproducer: web-trx auto-restore (which calls
probe_with_timeoutat startup) followed bybuild_sourcein the sameconnect()call — the librtlsdr handle from the probe was not yet released by Python's GC whenbuild_sourceran.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_HZfrom 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_HZaligned to match.Test plan
rtlsdr_demod_write_reg failederrors in log after connectingpython3-soapysdrfallback path still works if SoapySDR import fails🤖 Generated with Claude Code