Overview
The test jstests/sharding/read_pref_cmd.js has been intermittently failing in the sharding_clustered_collections suite on enterprise-amazon-linux2023-arm64 after SERVER-111191 was backported to v8.0.
Root Cause
SERVER-111191 changed the profiler to discard writes to system.profile when it cannot acquire a lock within internalQueryGlobalProfilingLockDeadlineMs (default: 1ms on master, 0ms on v8.0 at time of backport). On a secondary under load—e.g. during replication batch application—the profiler can fail to acquire an IX lock on the database, causing the profile entry to be silently dropped.
read_pref_cmd.js relies on profiler entries to verify that commands were routed to the expected node. When an entry is discarded, the assertion assert.eq(getNumNodesCmdRanOn(...), 1) fires because it finds 0 matching entries instead of 1.
Fix
Set internalQueryGlobalProfilingLockDeadlineMs: 1000 on all replica set nodes before running the test. This gives the profiler 1 second to acquire the lock, sufficient to absorb transient contention from replication. This matches the pattern used in other profiler-dependent tests (e.g. profile_agg.js, profile3.js).