@codemod/mine-go-potential-concurrency-hazards
Public Insights-compatible codemod package for mining potential concurrency hazards in Go repositories.
Installation
bash
Usage
This package is read-only. It does not rewrite source files.
Workflow contract:
- Workflow name:
default - Step name:
mine_concurrency_hazards - Engine:
js-ast-grep - Language:
go
The codemod emits one metric:
potential_concurrency_hazard
Hazard types:
waitgroup_add_inside_goroutinemap_write_in_goroutineslice_append_in_goroutineouter_scope_variable_writeloop_variable_capturemultiple_channel_closeshared_pointer_mutationdouble_checked_lockingrequest_scoped_object_in_background_goroutine
Cardinality keys:
hazard_typepackage_namefile_pathfunction_namevariable_namevariable_kindgoroutine_presentinside_loopinside_mutex_lockinside_atomic_operationinside_sync_oncechannel_namestruct_typeframeworkseverity
Detection intent:
- flags
WaitGroup.Addcalls inside goroutines - flags map writes and slice appends from goroutines
- flags writes to outer-scope variables captured by goroutines
- flags loop variable capture in goroutines started inside loops
- flags repeated
close(...)calls on the same channel in the same function - flags likely shared pointer mutation patterns
- flags likely double-checked locking patterns
- flags request-scoped objects used from background goroutines
The package preserves the positioning language Potential concurrency hazards and intentionally does not describe these findings as Race conditions.
Insights
Metric documentation:
- Metric name:
potential_concurrency_hazard - Workflow step name:
mine_concurrency_hazards - Cardinality keys:
hazard_type,package_name,file_path,function_name,variable_name,variable_kind,goroutine_present,inside_loop,inside_mutex_lock,inside_atomic_operation,inside_sync_once,channel_name,struct_type,framework,severity
Example Insights JSSG package query:
- Source: Codemod package
@codemod/mine-go-potential-concurrency-hazards - Select:
Metric - Metric:
potential_concurrency_hazard - Group by:
hazard_type,severity - Dimension filters:
goroutine_present = true
The included fixtures keep source output unchanged and, when the harness supports metric snapshots, validate emitted metrics.json snapshots for representative hazards.
Development
bash
License
MIT