Tags: nrwl/nx
Tags
Revert "feat(core): make console daemon check backgroundable and pull… ( #33578) ## Current Behavior PR #33491 introduced a daemon call into every command and caused unexpected issues... ## Expected Behavior the change is reverted while we investigate a proper fix ## Changes This reverts commit 9471207 from PR #33491. ## Related Issue(s) Fixes #33472
cleanup(gradle): fix gradle dsl e2e test in verbose mode (#33546) <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior the JSON parsing is broken because in verbose mode, the gradle plugin returns more than just JSON. ## Expected Behavior JSON parsing in the test should work ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
fix(core): resolve all lock ordering deadlocks in metrics collector (#… …33513) ## Summary This PR fixes a critical deadlock issue in the metrics collector that occurred due to inconsistent lock acquisition order between the collection thread and registration threads. The fix involved restructuring lock scopes across multiple functions to maintain a consistent lock hierarchy. ## Changes - Fixed lock acquisition order in 4 registration functions (register_main_cli_process, register_main_cli_subprocess, register_task_process, register_batch) - Restructured collect_metrics() to minimize system lock scope and release it before acquiring other locks - Fixed collection helper methods to read PIDs in scoped blocks without holding system lock - Added comprehensive trace logging for debugging lock contentions - Added concurrent test case to verify no deadlocks occur under stress ## Testing - All 12 metrics tests pass - Comprehensive concurrent stress test added: test_concurrent_group_creation_with_subprocess_updates - Lock ordering consistency test added: test_lock_order_consistency_across_registration_threads ## Lock Ordering Rule Established and enforced this hierarchy across all threads: 1. Acquire system lock first 2. Release system lock 3. Then acquire registration/PID locks This prevents circular wait conditions (A→B / B→A) that cause deadlocks. --------- Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>
fix(core): prevent hanging between command end and process exit (#33500) ## Current Behavior In certain scenarios, Nx commands would hang between command completion and process exit. This was caused by inefficient message end detection in the daemon socket communication, where the check for `MESSAGE_END_SEQ` could fail when TCP packets were fragmented. ## Expected Behavior With this PR, the message end detection is more robust and handles TCP packet fragmentation correctly, preventing the hanging issue. The changes also add better performance tracking and logging to help diagnose similar issues in the future. ## Changes Made - **Improved message end detection** (`consume-messages-from-socket.ts`): Added a preliminary check of the last character's code point before checking the full MESSAGE_END_SEQ, which prevents false negatives when TCP packets are fragmented - **Enhanced performance tracking** (`daemon/client/client.ts`, `daemon-socket-messenger.ts`): Added message-type-specific performance marks and measures for better debugging - **Added server-side logging** (`daemon/server/server.ts`): Added logging for message receipt, serialization, and response to help diagnose communication issues ## Related Issue(s) This fix addresses hanging issues observed in daemon communication when commands complete but the process doesn't exit.
chore(core): restructure metrics collector for performance and mainta… …inability (#33483) ## Current Behavior The metrics collector has several inefficiencies and architectural issues: - Complex hierarchical data structure (`ProcessTreeMetrics`) that doesn't align with how the data is consumed - Separate `MetadataStore` struct with unnecessary indirection - Full metadata resent to all subscribers on every collection cycle - Mutable parameters passed through collection functions instead of functional return values - Repeated allocations and clones across collection cycles - `CollectionRunner` tightly coupled to NAPI, making it untestable in pure Rust ## Expected Behavior This PR restructures the metrics collector for better performance, testability, and maintainability: ### Architectural Changes 1. **Flat Process Model**: Replaced hierarchical `ProcessTreeMetrics` with a flat `Vec<ProcessMetrics>`, simplifying data flow 2. **Group-Based Organization**: Introduced `GroupInfo` and `GroupType` to logically organize processes: - `MainCLI` - Nx CLI process and its subprocesses - `Daemon` - Nx daemon and its children - `Task` - Individual task execution processes - `Batch` - Batch execution with multiple tasks 3. **Incremental Metadata Updates**: - Track which groups and processes have been sent using `Arc<DashMap<String, GroupInfo>>` and `Arc<DashMap<String, ProcessMetadata>>` - Only send new metadata to subscribers instead of full state every cycle - New subscribers receive full metadata on first update via `needs_full_metadata` flag - Automatic cleanup of dead process/group metadata 4. **Shared State with Arc**: - Metadata maps shared between `ProcessMetricsCollector` and `CollectionRunner` using `Arc<DashMap>` - Eliminated duplicate metadata storage - Single source of truth for all metadata 5. **Functional Programming Pattern**: - Collection functions now return `Result<MetricsCollectionResult>` instead of mutating parameters - Cleaner error handling with `inspect_err` and `map` - Easier to reason about data flow - Removed ~100 lines of code by consolidating logic 6. **Channel-Based Communication**: - Decoupled `CollectionRunner` from NAPI using `crossbeam_channel` - Collection thread sends metrics via channel to listener thread - Listener thread receives metrics and notifies NAPI subscribers - `CollectionRunner` is now NAPI-free and fully testable in pure Rust - Non-blocking collection (subscriber callbacks don't block metrics collection) ### Performance Optimizations - Pre-allocated `Vec` capacity when combining metrics from different sources - Eliminated unnecessary `HashMap` clones during metadata updates - Single-pass insertion into `DashMap` during string key conversion - Reduced memory allocations in hot paths - Collection thread never blocks on JavaScript callbacks ### Code Quality Improvements - **Testability**: Added 7 pure Rust unit tests for `CollectionRunner`: - Group creation with different registration types - Incremental metadata updates - Dead group cleanup - All tests pass without requiring NAPI/Node.js runtime - Clearer separation of concerns between collection and notification - Better comments explaining incremental update strategy - More idiomatic Rust patterns throughout - Updated TypeScript type exports to match new structure ### Threading Model **Before:** ``` CollectionRunner (mixed collection + NAPI notification) ``` **After:** ``` CollectionRunner (pure Rust, testable) └─> Channel └─> Listener Thread └─> NAPI ThreadsafeFunction └─> Subscribers ``` ## Testing - ✅ 241 Rust tests passing (including 7 new `CollectionRunner` tests) - ✅ Native module builds successfully - ✅ TypeScript types updated and exports verified ## Related Issue(s) Part of ongoing metrics collector optimization work.
fix(js): skip TS project references migration for non-TS-solution wor… …kspaces (#33467) ## Current Behavior The `remove-redundant-ts-project-references` migration fails with an error when run on workspaces that don't have a root `tsconfig.json` file, such as nx-examples. ## Expected Behavior The migration should skip workspaces that are not using TypeScript solution setup instead of throwing an error. ## Related Issue(s) Fixes the issue encountered when running the migration on nrwl/nx-examples repo. ## Changes - Added check to skip migration if workspace is not using TS solution setup - Updated test setup to properly configure TS solution for existing tests - Added new test cases to verify skip behavior The migration now uses `isUsingTsSolutionSetup()` to detect if: - `tsconfig.base.json` exists - `tsconfig.json` exists and extends the base - Package manager workspaces are configured - Proper TS solution structure is in place Workspaces missing any of these requirements will have the migration skip silently. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
chore(js): update migration version to 22.1.0-rc.1 (#33465) ## Current Behavior The migration for removing redundant TypeScript project references is set to version `22.1.0-beta.8`. ## Expected Behavior The migration should be updated to version `22.1.0-rc.1` to align with the release candidate version. ## Related Issue(s) N/A - Version update as requested.
PreviousNext