Aalexbit-codemod

go-concurrency-hazard-mining

Mine potential Go concurrency hazards; read-only metrics with confidence/protection scoring and mutex-aware false-positive suppression

miningmetricsgoconcurrencygoroutinerace-reviewkraken
Public
2 executions

Run locally

npx codemod go-concurrency-hazard-mining

go-concurrency-hazard-mining

Read-only mining codemod that surfaces potential concurrency hazards in Go
source. Findings are suspicious patterns suitable for review, go test -race,
or remediation — not proven data races.

Static analysis can identify risky patterns but cannot prove that two goroutines
access the same memory concurrently, that a write overlaps another access at
runtime, or that no happens-before relationship exists. Treat output as
high-signal review candidates.

v0.2.0 — false-positive reduction

Protected writes (mutex, atomic, sync.Once) on shared slices/maps/scalars are
suppressed by default. Use emit_low_confidence=true to include them for
audit trails.

New metric cardinalities:

fieldvalues
confidencehigh, medium, low
protectionmutex, atomic, sync_once, none

Mutex detection pairs Lock/RLock with matching Unlock/RUnlock on the
same receiver, including nested if blocks and defer mu.Unlock() patterns
(e.g. Kraken PrefetchHandler errList aggregation).

Workflow parameters

paramdefaultdescription
include_teststrueSet false to skip *_test.go (production-only scans)
emit_low_confidencefalseSet true to emit mutex-protected writes at confidence=low

Hazard types

hazard_typeSeveritySuppressed when protected?
waitgroup_add_inside_goroutinehighnever
map_write_in_goroutinehighyes (mutex/atomic/once)
slice_append_in_goroutinehighyes
outer_scope_variable_writemediumyes
shared_pointer_mutationmediumyes
loop_variable_capturemediumwhen loop var passed as closure arg
multiple_channel_closemediumnever
double_checked_lockingmediumnever
request_scoped_object_in_background_goroutinemediumnever

Run locally

bash

Ready to contribute?

Build your own codemod and share it with the community.