Fix/uorb listener fetch only sensors - #3686
Closed
FelipeMdeO wants to merge 4 commits into
Closed
Conversation
orb_subscribe_multi() opens the descriptor blocking, so a sensor whose lower half only implements fetch() (no push, e.g. an I2C part with no interrupt line) never satisfies poll()/read() and the listener silently times out with zero messages, indistinguishable from a sensor that has nothing to report. Set O_NONBLOCK after subscribing; sensors that do push samples are unaffected, since neither sensor_poll() nor sensor_read() consults O_NONBLOCK on that path. Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
The upper half accepts SNIOC_SET_INTERVAL and stores it even when the lower half has no set_interval, but only applies it to samples that are pushed into the circular buffer. A fetch()-only sensor was therefore read as fast as the poll loop could run instead of at the rate given with -r. Sleep out the remainder of the period; this is a no-op for sensors where poll() already waited for it. Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
orb_info() is compiled under UORB_FORMAT and formats through the "%pB" extension, but only DEBUG_UORB selected LIBC_PRINT_EXTENSION. Enabling the listener alone therefore printed the raw buffer address instead of the decoded data, e.g. "sensor_accel(now:390000):0x3fc931e4B". Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
"%pB" nests a second formatting pass, and the listener peaked at 2256 bytes of stack (measured with STACK_COLORATION), which does not fit in a DEFAULT_TASK_STACKSIZE of 2048. The overflow did not fail cleanly: it corrupted memory outside the task, surfacing as an unrelated assertion in another task's mutex. Default to 4096 when UORB_FORMAT is enabled. Signed-off-by: Felipe Moura <moura.fmo@gmail.com>
cederom
approved these changes
Jul 31, 2026
cederom
left a comment
Contributor
There was a problem hiding this comment.
Thank you @FelipeMdeO :-)
CI fix should jump in soon :-)
acassis
approved these changes
Jul 31, 2026
| static int listener_subscribe(FAR struct listen_object_s *tmp, | ||
| bool nonwakeup) | ||
| { | ||
| int flags; |
Contributor
There was a problem hiding this comment.
it's better to let sensor upperhalf layer always return POLLIN for the fetch only sensor
Contributor
Author
There was a problem hiding this comment.
I agree.
I've been avoiding messing with the kernel, I'm going to stop doing that.
| { | ||
| orb_abstime elapsed = orb_absolute_time() - start; | ||
|
|
||
| if (elapsed < (orb_abstime)interval) |
| { | ||
| orb_abstime start = orb_absolute_time(); | ||
|
|
||
| if (poll(&fds[0], nb_objects, timeout * 1000) > 0) |
Contributor
There was a problem hiding this comment.
how about let driver return one POLLIN in each interval for fetch only sensor
|
|
||
| config UORB_STACKSIZE | ||
| int "stack size" | ||
| default 4096 if UORB_FORMAT |
Contributor
There was a problem hiding this comment.
let's change to 4KB always?
Contributor
Author
|
I will move close this PR to follow Xiang request, fix issue in upperhalf, in Nuttx folder. |
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
uorb_listenernever showed data for a sensor whose lower half onlyimplements
fetch()(the usual case for an I2C part with no interruptline wired, e.g. the MPU6050):
orb_subscribe_multi()opens thedescriptor blocking, and a fetch()-only sensor never pushes a sample
into the circular buffer, so
sensor_poll()/sensor_read()waitforever. The 5-second timeout was silent and indistinguishable from a
sensor that genuinely has nothing to report.
Four fixes, one per commit:
O_NONBLOCKon the descriptor after subscribing — the core fix,makes fetch()-only sensors visible to the listener at all.
-r) for fetch()-only sensors — the upperhalf only applies
SNIOC_SET_INTERVALto pushed samples, so withoutthis the loop read as fast as it could run.
LIBC_PRINT_EXTENSIONfromUORB_FORMAT— without it,orb_info()'s"%pB"extension printed the raw buffer addressinstead of the decoded data.
UORB_STACKSIZEto 4096 whenUORB_FORMATisenabled — the nested
"%pB"formatting pass peaked at ~2.2KB(measured with
STACK_COLORATION), overflowing the 2048 bytedefault and corrupting memory outside the task rather than failing
cleanly.
Impact
Affects any board using
uorb_listeneron a uORB sensor whose lowerhalf only implements
fetch(). Push-based sensors are unaffected:neither
sensor_poll()norsensor_read()consultsO_NONBLOCKonthat path.
UORB_STACKSIZEdefault only changes for configs thatalready select
UORB_FORMAT(i.e. already use the listener).Testing
Target: ESP32-S3-DevKitC (N16R8) with a GY-521 (MPU6050) on I2C0 (SDA
GPIO5 / SCL GPIO4),
esp32s3-devkit:mpu6050defconfig(
EXAMPLES_SENSOR_FUSIONdisabled just for this test, since it needsa separate unmerged fix and is unrelated to this bug).
Before (apps master,
5f286fc92, without this fix):The sensor was confirmed alive and publishing via
sensortestat thesame time.
After (this branch,
6fe80c8ad):Accelerometer Z reads gravity with the board resting flat, gyroscope
reads near zero, both topics interleave correctly, and the 10 Hz rate
requested with
-ris honored (~110ms between samples).