#810 Fix race condition in IncExecution and IncError
Pull request opened by
kimjune01
The previous implementation had a race condition where multiple goroutines could read the same counter value, increment it, and write back, causing lost updates under concurrent load.
The read-modify-write cycle allowed this scenario:
1. Thread A reads: executions = 5
2. Thread B reads: executions = 5 (same value)
3. Thread A writes: executions = 6
4. Thread B writes: executions = 6 (should be 7)
Fixed by using atomic database operations with gorm.Expr to perform the increment directly in SQL:
UPDATE distributed_queries SET executions = executions + 1 WHERE ...
This ensures thread-safe atomic increments even under concurrent load, matching the pattern used for IncExpected in the same file.
jmpsec/osctrl