Skip to content

sched/signal: Recheck pending sigtimedwait signals - #21065

Merged
casaroli merged 1 commit into
apache:masterfrom
anchao:26102806
Nov 1, 2026
Merged

casaroli merged 1 commit into
apache:masterfrom
anchao:26102806

Conversation

@anchao

@anchao anchao commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix a race in the sigtimedwait() wait path where a matching signal could
remain pending while the waiting task goes to sleep.

sigtimedwait() publishes sigwaitmask before calling nxsig_clockwait().
If a matching signal is queued after that publication but before the task is
moved to TSTATE_WAIT_SIG, the signal can remain pending while the task still
blocks waiting for it.

This change rechecks the task's pending signal set inside nxsig_clockwait()
while interrupts are disabled. If a pending signal matches sigwaitmask, it is
removed from the pending queue, copied into sigunbinfo, and returned
immediately instead of blocking the task.

Impact

This fixes a signal wait race that could cause sigtimedwait() to sleep even
though a waited-for signal is already pending.

Expected impact:

  • prevents missed wakeups in the sigtimedwait() path
  • preserves normal blocking behavior when no matching signal is pending
  • consumes and reports the lowest-numbered matching pending signal
  • avoids changing behavior when signals are disabled
  • no API, ABI, build-system, documentation, or security impact is expected

Testing

sim/nsh

@github-actions github-actions Bot added Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

esp32-devkitc

  • ROM: .flash.text +108 B (+0.1%, 127,616 B / 4,194,272 B, total: 3% used)
  • irom0_0_seg: .flash.text +108 B (+0.1%, 93,592 B / 3,342,304 B, total: 3% used)

hifive1-revb

  • flash: .text +108 B (+0.1%, 84,428 B / 4,194,304 B, total: 2% used)

qemu-armv8a

  • Code: .rodata +24 B, .text.nxsig_clockwait +136 B, .text.nxsig_timedwait +4 B (+0.0%, 352,924 B)

qemu-intel64

  • Code: .text +255 B (+0.0%, 8,686,476 B)
  • Data: .rodata +64 B (+0.1%, 125,081 B)

rx65n-rsk2mb

  • ROM: .text +128 B (+0.1%, 89,592 B / 2,097,152 B, total: 4% used)

s698pm-dkit

  • Code: .text +352 B (+0.1%, 380,992 B)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@casaroli casaroli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The Testing section has only "sim/nsh" with no log, and this head does not build on sim (CI sim-01).

Fix: add the build and runtime logs of this head.

Comment thread sched/signal/sig_clockwait.c Resolved
Comment thread sched/signal/sig_clockwait.c Resolved
sigtimedwait() publishes sigwaitmask before nxsig_clockwait() moves the task
to TSTATE_WAIT_SIG. A matching signal queued in that window can remain
pending while the waiter goes to sleep.

Recheck and consume matching pending signals in nxsig_clockwait() while
interrupts are disabled before blocking the task.

Signed-off-by: chao an <[email protected]>

@casaroli casaroli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Testing section still says only "sim/nsh", with no log; our review of 08:08Z asked for the logs too.

Fix: add the build and runtime logs of this head (CONTRIBUTING 1.7.2), with a test where a signal is sent between the sigwaitmask setting and the wait (for example a higher-priority thread or an interrupt that posts it), the case this PR fixes.

@casaroli
casaroli merged commit c066c48 into apache:master Nov 1, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants