[Paper Review] Static Race Detection and Mutex Safety and Liveness for Go Programs
This paper presents the first static verification framework for Go programs that uniformly detects data races, deadlocks, and mutex safety/liveness violations using behavioural types and type-level model checking. It formalizes Go's happens-before relation in a µ-calculus type model, enabling sound, static analysis of concurrency bugs arising from both shared memory and channel communication.
Go is a popular concurrent programming language thanks to its ability to efficiently combine concurrency and systems programming. In Go programs, a number of concurrency bugs can be caused by a mixture of data races and communication problems. In this paper, we develop a theory based on behavioural types to statically detect data races and deadlocks in Go programs. We first specify lock safety/liveness and data race properties over a Go program model, using the happens-before relation defined in the Go memory model. We represent these properties of programs in a μ-calculus model of types, and validate them using type-level model-checking. We then extend the framework to account for Go’s channels, and implement a static verification tool which can detect concurrency errors. This is, to the best of our knowledge, the first static verification framework of this kind for the Go language, uniformly analysing concurrency errors caused by a mix of shared memory accesses and asynchronous message-passing communications.
Motivation & Objective
- To address the lack of static analysis tools for Go concurrency bugs combining shared memory and message-passing issues.
- To formalize Go's memory model using a happens-before relation within a behavioural type system.
- To develop a unified static verification framework that checks both safety (data races, deadlocks) and liveness (mutex fairness) in Go programs.
- To enable scalable, sound verification of Go programs using type-level model checking with mCRL2.
- To overcome limitations of dynamic race detectors like Go's -race flag, which suffer from high overhead and incomplete detection.
Proposed method
- Formalize Go's concurrency semantics using a process calculus model extended with shared memory and channels.
- Define lock safety and liveness properties using the happens-before relation from the Go memory model.
- Represent program properties as µ-calculus formulas over behavioural types for static verification.
- Use type-level model checking via mCRL2 to validate safety and liveness properties without runtime overhead.
- Extend the framework to handle Go's channels and goroutine spawning, including dynamic process creation.
- Implement a prototype tool that extracts Go code into a formal GoL-like intermediate language for analysis.
Experimental results
Research questions
- RQ1Can behavioural types and type-level model checking be used to statically verify both data races and deadlocks in Go programs?
- RQ2How can the happens-before relation in the Go memory model be formally encoded and used to detect data races and mutex safety violations?
- RQ3Can a unified static analysis framework effectively handle both shared-memory concurrency and message-passing via channels in Go?
- RQ4How does the proposed framework compare in precision and scalability to dynamic race detectors like Go's -race flag?
- RQ5Can the framework be extended to support dynamic process creation and provide counterexamples for detected bugs?
Key findings
- The proposed framework is the first to statically verify both data races and deadlock/liveness issues in Go programs using a unified behavioural type model.
- The use of type-level model checking with mCRL2 enables sound verification without runtime overhead, unlike dynamic detectors such as ThreadSanitizer.
- The framework successfully detects the data race in Figure 1 (unsafe RWMutex usage) and correctly identifies the safe version in Figure 2.
- The approach supports both read-write mutexes and channel-based communication, covering a broad class of concurrency bugs in Go.
- The tool prototype demonstrates feasibility and correctness on real Go programs, with formal validation via model checking.
- The work identifies gaps in existing dynamic detectors, such as limited history and false negatives on non-blocking bugs, which the static approach helps overcome.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.