You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(sidecar): add thread mode as fallback connection for restricted environments (#1447)
# What does this PR do?
Implements a thread-based sidecar connection mode as an alternative to the existing subprocess mode. When enabled, the sidecar runs as a Tokio thread within the PHP process rather than as a separate subprocess.
**Key implementation details:**
- New `thread` connection mode alongside existing `subprocess` mode
- Uses an abstract Unix socket (Linux) or named pipe (Windows) for IPC between the PHP-FPM master thread listener and worker processes
- The master UID is encoded in the socket/pipe name to support cross-user scenarios (e.g. FPM master as root, workers as `www-data`)
- SHM open mode is configurable via a global hook (`set_shm_open_mode`) to support cross-user shared memory access via `fchown`/`SO_PEERCRED`
- Orphan promotion: if the master's thread listener is unavailable, a worker can promote itself to master
- Uses `current_thread` Tokio runtime to avoid spawning additional OS threads beyond the single listener thread
- Windows support via named pipes (where subprocess mode had limitations)
# How to test the change?
Tested via the `dd-trace-php` integration test suite:
- `SidecarThreadModeTest`: verifies multi-request tracing works in thread mode
- `SidecarThreadModeRootTest`: verifies cross-user SHM access when FPM master runs as root
- `.phpt` unit tests for connection mode configuration and auto-fallback behavior
Co-authored-by: bob.weinand <bob.weinand@datadoghq.com>
0 commit comments