返回提示词目录第 1363 页

竞态条件排查与并发故障验证

梳理共享状态及并发执行者,以交错时序证明错误状态,输出竞态报告、修复措施和确定性回归测试。

完整提示词

# RACE CONDITION AND CONCURRENCY HUNTER

I want a deep analysis of all concurrency, race and interleaving failure paths in the application.

Main objective:

> Find situations in which two or more legitimate execution paths read or change shared state at the same time and can violate a business invariant, even when each path is correct on its own.

This is not:

- only a thread race audit
- an automatic recommendation to add a lock
- an assumption that a database transaction solves every race
- an assumption that JavaScript/single-threaded means no concurrency problems

## 1. SHARED STATE INVENTORY

- DB rows
- cache
- files
- memory
- queue
- external API
- distributed resource
- counters
- quotas
- inventory
- session

## 2. CONCURRENT ACTORS

- requests
- workers
- schedulers
- retries
- webhooks
- users
- devices
- tabs

## 3. INVARIANT

## 4. READ-MODIFY-WRITE

## 5. CHECK-THEN-ACT

## 6. CHECK-THEN-INSERT

## 7. LOST UPDATE

## 8. DUPLICATE CREATE

## 9. WRITE SKEW

## 10. STALE WRITE

## 11. DELETE/UPDATE

## 12. REVOKE/USE

## 13. EXPIRE/RENEW

## 14. QUOTA

## 15. BALANCE

## 16. INVENTORY

## 17. SEQUENCE

## 18. UNIQUE CONSTRAINT

## 19. UPSERT

## 20. ATOMIC UPDATE

## 21. TRANSACTION

## 22. ISOLATION

Engine-specific.

## 23. OPTIMISTIC LOCK

## 24. VERSION COLUMN

## 25. PESSIMISTIC LOCK

## 26. DEADLOCK

## 27. LOCK ORDER

## 28. LOCK TIMEOUT

## 29. LONG TRANSACTION

## 30. RETRY

## 31. SERIALIZATION FAILURE

## 32. REPLICA

## 33. STALE READ

## 34. READ-AFTER-WRITE

## 35. CACHE

## 36. CACHE INVALIDATION

## 37. DOUBLE CACHE FILL

## 38. DISTRIBUTED LOCK

## 39. LEASE

## 40. TTL

## 41. FENCING TOKEN

## 42. CLOCK

## 43. LEADER

## 44. DUPLICATE WORKER

## 45. QUEUE DUPLICATE

## 46. OUT-OF-ORDER

## 47. RETRY AFTER SUCCESS

## 48. IDEMPOTENCY KEY

## 49. SAME KEY CONCURRENCY

## 50. BACKGROUND JOB

## 51. SCHEDULER OVERLAP

## 52. WEBHOOK

## 53. PAYMENT

## 54. FILE

## 55. OBJECT STORAGE

## 56. EXTERNAL API

## 57. UNKNOWN OUTCOME

## 58. MULTI-SERVICE

## 59. SAGA

## 60. EVENTUAL CONSISTENCY

## 61. SESSION

## 62. MULTI-TAB

## 63. MULTI-DEVICE

## 64. PERMISSION CHANGE

## 65. AUTH CACHE

## 66. FEATURE FLAG CHANGE

## 67. CONFIG CHANGE

## 68. PROCESS RESTART

## 69. DEPLOYMENT

## 70. OLD/NEW VERSION

## 71. INTERLEAVING PROOF

For each race, write:

```text
T1:
T2:
```

step by step.

## 72. DETERMINISTIC REPRO

Use:

- barrier
- latch
- hooks
- test transaction coordination

## 73. STRESS TEST

Useful after deterministic proof.

## 74. TSAN/RACE DETECTOR

Where applicable.

## 75. DB LOCK INSPECTION

## 76. TRACE

## 77. FALSE POSITIVE RULES

Do not report a race only because:

- two requests can run concurrently
- lock missing
- transaction absent

There must be shared state + a harmful interleaving.

## 78. EVIDENCE TIERS

```text
A - deterministically reproduced race
B - complete interleaving proof
C - strong static concurrency evidence
D - plausible interleaving requiring test
E - hardening
```

## 79. STATUS

```text
CONFIRMED
LIKELY
NOT VERIFIED
CONTROLLED
NOT APPLICABLE
HARDENING
```

## 80. SEVERITY

P0:
catastrophic corruption/security concurrency failure

P1:
repeatable duplicate money/data loss/authorization race

P2:
material consistency problem

P3:
limited conflict

P4:
hardening

## 81. FINDING FORMAT

```text
ID:
Severity:
Status:
Evidence tier:
Invariant:
Shared state:
Actors:
T1:
T2:
Harmful interleaving:
Current protection:
Why insufficient:
Impact:
Evidence:
Fix:
Deterministic regression test:
```

## 82. CONCURRENCY MATRIX

| Resource | Actors | Invariant | Atomicity | Race protected |
|---|---|---|---|---|

## 83. SECOND PASS

Search:

- all read-modify-write
- existence checks
- balance/quota
- unique creation
- retry paths
- duplicate events
- scheduler
- permission change
- distributed locks
- cache invalidation
- process restart

## 84. FINAL QUALITY GATE

Confirm:

- shared state
- actors
- interleaving
- transaction semantics
- isolation
- locks
- retries
- queue
- external side effects
- deterministic tests
- false positives

## 85. OUTPUT

`RACE_CONDITION_CONCURRENCY_HUNTER.md`

## 86. FAILURE CHAIN

```text
T1 reads stock = 1
T2 reads stock = 1

T1 validates stock > 0
T2 validates stock > 0

T1 writes stock = 0
T2 writes stock = 0
↓
two orders accepted for one item
```

# FINAL RULE

A race finding is not:

```text
"this code might run concurrently"
```

but proof of:

```text
shared invariant
+
two valid actors
+
specific interleaving
+
wrong final state
```

分类与标签

编程开发、竞态条件、并发测试、共享状态、交错时序、分布式锁

前往 AI 图片创作