FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(px4_daemon): fix startup stdout TLS race by katzfey · Pull Request #28013 · PX4/PX4-Autopilot · GitHub

fix(px4_daemon): fix startup stdout TLS race - #28013

Merged
katzfey merged 2 commits into
mainfrom
pr-fix-px4-daemon-race
Jul 22, 2026
Merged

katzfey merged 2 commits into
mainfrom
pr-fix-px4-daemon-race

Conversation

katzfey commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Solved Problem

Fixes a px4_daemon startup race where the daemon could be considered running before its thread-local stdout
pthread_key_t was created. Early startup logging could then try to use daemon stdout handling with an invalid/
uninitialized TLS key, leading to invalid FILE * behavior.

Solution

Create the daemon stdout TLS key during Server construction, before the server is exposed as the active daemon
instance. Track whether the key was created successfully, fail Server::start() if it was not, and delete the key
only when valid.

get_stdout() now also checks that the server has a valid pthread key before using daemon thread-local stdout, so
early or fallback logging safely uses normal stdout.

Changelog Entry

For release notes:

Bugfix: Fix px4_daemon startup stdout thread-local storage race

Alternatives

The key could remain created inside the server thread with additional guards around stdout access, but that keeps
startup ordering fragile. Creating the key before the daemon is marked available makes the lifetime and readiness
contract explicit.

Test coverage

Tested on VOXL2 board

Create the server thread-local stdout key before marking the daemon as
running, preventing early startup logs from using an invalid FILE pointer.
katzfey requested review from dirksavage88 and mrpollo July 21, 2026 16:41
katzfey self-assigned this Jul 21, 2026
github-actions Bot added kind:bug Something is broken or behaving incorrectly. scope:simulation SITL, Gazebo, jmavsim, lockstep, or simulated sensors. labels Jul 21, 2026

github-actions Bot commented Jul 21, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

🔎 FLASH Analysis

px4_fmu-v5x [Total VM Diff: 0 byte (0 %)]
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +55  [ = ]       0    .debug_abbrev
  -0.0%      -2  [ = ]       0    .debug_info
  -0.0%     -13  [ = ]       0    .debug_line
   -85.7%      -6  [ = ]       0    [Unmapped]
    -0.0%      -7  [ = ]       0    [section .debug_line]
  +0.0%     +40  [ = ]       0    TOTAL

px4_fmu-v6x [Total VM Diff: 0 byte (0 %)]
    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%     +55  [ = ]       0    .debug_abbrev
  -0.0%      -2  [ = ]       0    .debug_info
  -0.0%     -13  [ = ]       0    .debug_line
   -85.7%      -6  [ = ]       0    [Unmapped]
    -0.0%      -7  [ = ]       0    [section .debug_line]
  +0.0%     +40  [ = ]       0    TOTAL

Updated: 2026-07-22T16:54:15

katzfey merged commit cbe8680 into main Jul 22, 2026
75 of 77 checks passed
katzfey deleted the pr-fix-px4-daemon-race branch July 22, 2026 17:37
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

Labels

kind:bug Something is broken or behaving incorrectly. scope:simulation SITL, Gazebo, jmavsim, lockstep, or simulated sensors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL