Abstract
Detecting concurrency bugs in Go programs can be a challenging task due to the language’s built-in support for concurrency through goroutines and channels. This paper proposes GoGuard, an efficient and precise static concurrency bug detector generalized for both traditional and Go-specific blocking bugs. This generic solution is powered by Resource Flow Graph which captures the communication mechanism among different Go concurrency primitives by a producer-consumer concept and detects blocking bugs by finding unmatched producers and consumers. Moreover, Resource Flow Graph incorporates happens-before relations in the same manner, which inspires our may-happen-in-parallel analysis, Static Happens-In-Parallel Simulation, that achieves randomness akin to real-world execution and avoids expensive graph traversal. We evaluate GoGuard on GoBench and large, real-world Go projects, e.g. gRPC, Istio, Etcd and Serving. We also compare with GCatch, a state-of-the-art Go concurrency bug detector. The result demonstrates the efficiency and precision of GoGuard: GoGuard is 30x faster on real-world Go projects and detects 10 more true blocking bugs than GCatch.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
CockroachDB1055 and 1462 have omitted more details and introduce new bugs, which are excluded from our evaluation.
References
Cockroachdb. https://github.com/cockroachdb/cockroach
Cockroachdb issue: sqlstats: Persistedsqlstats.stop() blocking server drain. https://github.com/cockroachdb/cockroach/issues/102574
Cockroachdb pull request: sql,persistedsqlstats: prevent a deadlock during shutdown. https://github.com/cockroachdb/cockroach/pull/102590
fix deadlock when more than 1 plugin is installed by vieux:Pull Request#25384:moby. https://github.com/moby/moby/pull/25384/commits/42360d164b9f25fb4b150ef066fcf57fa39559a7
Go tools. https://pkg.go.dev/golang.org/x/tools
grpc-go/server.go - github.com. https://github.com/grpc/grpc-go/blob/b128e7465a03dbf5359f95abe14fc2caa670c36e/server.go#L798
Kubernetes. https://github.com/kubernetes/kubernetes
Albert, E., Genaim, S., Gordillo, P.: May-happen-in-parallel analysis for asynchronous programs with inter-procedural synchronization. In: Sensors Applications Symposium (2015). https://api.semanticscholar.org/CorpusID:14081258
Angerer, C.M., Gross, T.R.: Now happens-before later: Static schedule analysis of fine-grained parallelism with explicit happens-before relationships. In: Proceedings of the ACM International Conference Companion on Object Oriented Programming Systems Languages and Applications Companion, OOPSLA 2010, pp. 3–10. Association for Computing Machinery, New York, NY, USA (2010). https://doi.org/10.1145/1869542.1869544
Byrd, G., Flynn, M.: Producer-consumer communication in distributed shared memory multiprocessors. Proc. IEEE 87(3), 456–466 (1999). https://doi.org/10.1109/5.747866
Chabbi, M., Ramanathan, M.K.: A study of real-world data races in golang. In: Proceedings of the 43rd ACM SIGPLAN International Conference on Programming Language Design and Implementation, PLDI 2022, pp. 474–489. Association for Computing Machinery, New York, NY, USA (2022). https://doi.org/10.1145/3519939.3523720
Dilley, N., Lange, J.: Automated verification of go programs via bounded model checking. In: Proceedings of the 36th IEEE/ACM International Conference on Automated Software Engineering, ASE 2021, pp. 1016–1027. IEEE Press (2022). https://doi.org/10.1109/ASE51524.2021.9678571
Dilley, N., Lange, J.: Automated verification of concurrent go programs via bounded model checking. Autom. Softw. Eng. 30(2), 29 (2023). https://doi.org/10.1109/ASE51524.2021.9678571
Engler, D., Ashcraft, K.: Racerx: effective, static detection of race conditions and deadlocks. In: Proceedings of the Nineteenth ACM Symposium on Operating Systems Principles, SOSP 2003, pp. 237–252. Association for Computing Machinery, New York, NY, USA (2003). https://doi.org/10.1145/945445.945468
Gabet, J., Yoshida, N.: Static race detection and mutex safety and liveness for go programs (extended version). CoRR abs/2004.12859 (2020). https://doi.org/10.48550/arXiv.2004.12859
Inverso, O., Nguyen, T.L., Fischer, B., La Torre, S., Parlato, G.: Lazy-cseq: a context-bounded model checking tool for multi-threaded C-programs. In: Proceedings of the 30th IEEE/ACM International Conference on Automated Software Engineering, ASE 2015, pp. 807–812. IEEE Press (2015). https://doi.org/10.1109/ASE.2015.108
Jeffay, K.: The real-time producer/consumer paradigm: a paradigm for the construction of efficient, predictable real-time systems. In: Proceedings of the 1993 ACM/SIGAPP Symposium on Applied Computing: States of the Art and Practice, SAC 1993, pp. 796–804. Association for Computing Machinery, New York, NY, USA (1993). https://doi.org/10.1145/162754.168703
Kahlon, V., Sinha, N., Kruus, E., Zhang, Y.: Static data race detection for concurrent programs with asynchronous calls. In: Proceedings of the 7th Joint Meeting of the European Software Engineering Conference and the ACM SIGSOFT Symposium on The Foundations of Software Engineering, ESEC/FSE 2009, pp. 13–22. Association for Computing Machinery, New York, NY, USA (2009). https://doi.org/10.1145/1595696.1595701
Lamport, L.: Time, clocks, and the ordering of events in a distributed system. Commun. ACM 21(7), 558–565 (1978). https://doi.org/10.1145/359545.359563
Lange, J., Ng, N., Toninho, B., Yoshida, N.: Fencing off go: liveness and safety for channel-based programming. In: Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, pp. 748–761. Association for Computing Machinery, New York, NY, USA (2017). https://doi.org/10.1145/3009837.3009847
Lange, J., Ng, N., Toninho, B., Yoshida, N.: A static verification framework for message passing in go using behavioural types. In: Proceedings of the 40th International Conference on Software Engineering, ICSE 2018, pp. 1137–1148. Association for Computing Machinery, New York, NY, USA (2018). https://doi.org/10.1145/3180155.3180157
Liu, B., Huang, J.: D4: fast concurrency debugging with parallel differential analysis. In: Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2018, pp. 359–373. ACM, New York, NY, USA (2018). https://doi.org/10.1145/3192366.3192390
Liu, B., Liu, P., Li, Y., Tsai, C.C., Da Silva, D., Huang, J.: When threads meet events: efficient and precise static race detection with origins. In: Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation, PLDI 2021, pp. 725–739. Association for Computing Machinery, New York, NY, USA (2021). https://doi.org/10.1145/3453483.3454073
Liu, Z., Xia, S., Liang, Y., Song, L., Hu, H.: Who goes first? Detecting go concurrency bugs via message reordering. In: Proceedings of the 27th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, ASPLOS 2022, pp. 888–902. Association for Computing Machinery, New York, NY, USA (2022). https://doi.org/10.1145/3503222.3507753
Liu, Z., Zhu, S., Qin, B., Chen, H., Song, L.: Automatically detecting and fixing concurrency bugs in go software systems. In: Proceedings of the 26th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, ASPLOS 2021, pp. 616–629. Association for Computing Machinery, New York, NY, USA (2021). https://doi.org/10.1145/3445814.3446756
Naik, M., Aiken, A., Whaley, J.: Effective static race detection for Java. In: Proceedings of the 27th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2006, pp. 308–319. Association for Computing Machinery, New York, NY, USA (2006). https://doi.org/10.1145/1133981.1134018
Ng, N., Yoshida, N.: Static deadlock detection for concurrent go by global session graph synthesis. In: Proceedings of the 25th International Conference on Compiler Construction, CC 2016, pp. 174–184. Association for Computing Machinery, New York, NY, USA (2016). https://doi.org/10.1145/2892208.2892232
Parízek, P., Jančík, P.: Approximating happens-before order: interplay between static analysis and state space traversal. In: Proceedings of the 2014 International SPIN Symposium on Model Checking of Software, SPIN 2014, pp. 1–10. Association for Computing Machinery, New York, NY, USA (2014). https://doi.org/10.1145/2632362.2632365
Pratikakis, P., Foster, J.S., Hicks, M.: Locksmith: context-sensitive correlation analysis for race detection. In: Proceedings of the 27th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2006, pp. 320–331. Association for Computing Machinery, New York, NY, USA (2006). https://doi.org/10.1145/1133981.1134019
Scalas, A., Yoshida, N., Benussi, E.: Verifying message-passing programs with dependent behavioural types. In: Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2019, pp. 502–516. Association for Computing Machinery, New York, NY, USA (2019). https://doi.org/10.1145/3314221.3322484
Shanbhag, V.K.: Deadlock-detection in Java-library using static-analysis. In: 2008 15th Asia-Pacific Software Engineering Conference, pp. 361–368 (2008). https://doi.org/10.1109/APSEC.2008.68
Swain, B., Li, Y., Liu, P., Laguna, I., Georgakoudis, G., Huang, J.: Ompracer: a scalable and precise static race detector for openmp programs. In: Proceedings of the International Conference for High Performance Computing, Networking, Storage and Analysis, SC 2020. IEEE Press (2020). https://api.semanticscholar.org/CorpusID:231793198
Tu, T., Liu, X., Song, L., Zhang, Y.: Understanding real-world concurrency bugs in go. In: Proceedings of the Twenty-Fourth International Conference on Architectural Support for Programming Languages and Operating Systems, ASPLOS 2019, pp. 865–878. Association for Computing Machinery, New York, NY, USA (2019). https://doi.org/10.1145/3297858.3304069
Veileborg, O.H., Saioc, G.V., Møller, A.: Detecting blocking errors in go programs using localized abstract interpretation. In: Proceedings of the 37th IEEE/ACM International Conference on Automated Software Engineering, ASE 2022. Association for Computing Machinery, New York, NY, USA (2023). https://doi.org/10.1145/3551349.3561154
Voitsechov, D., Port, O., Etsion, Y.: Inter-thread communication in multithreaded, reconfigurable coarse-grain arrays. In: 2018 51st Annual IEEE/ACM International Symposium on Microarchitecture (MICRO), pp. 42–54 (2018). https://doi.org/10.1109/MICRO.2018.00013
Voung, J.W., Jhala, R., Lerner, S.: Relay: static race detection on millions of lines of code. In: Proceedings of the the 6th Joint Meeting of the European Software Engineering Conference and the ACM SIGSOFT Symposium on The Foundations of Software Engineering, ESEC-FSE 2007, pp. 205–214. Association for Computing Machinery, New York, NY, USA (2007). https://doi.org/10.1145/1287624.1287654
Wu, D., Liu, J., Sui, Y., Chen, S., Xue, J.: Precise static happens-before analysis for detecting UAF order violations in android. In: 2019 12th IEEE Conference on Software Testing, Validation and Verification (ICST), pp. 276–287 (2019). https://doi.org/10.1109/ICST.2019.00035
Yu-tao, F., Sheng-chen, Y., Yang, X.: System for performing resource management and control and task scheduling in grid computing. In: 2008 International Symposium on Computer Science and Computational Technology, vol. 1, pp. 648–651 (2008). https://doi.org/10.1109/ISCSCT.2008.229
Yuan, T., Li, G., Lu, J., Liu, C., Li, L., Xue, J.: Gobench: a benchmark suite of real-world go concurrency bugs. In: 2021 IEEE/ACM International Symposium on Code Generation and Optimization (CGO), pp. 187–199. IEEE Computer Society, Los Alamitos, CA, USA (2021). https://doi.org/10.1109/CGO51591.2021.9370317
Zhan, S., Huang, J.: Echo: Instantaneous in situ race detection in the ide. In: Proceedings of the 2016 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering, FSE 2016, pp. 775–786. Association for Computing Machinery, New York, NY, USA (2016). https://doi.org/10.1145/2950290.2950332
Zhang, D., Qi, P., Zhang, Y.: Godetector: detecting concurrent bug in go. IEEE Access 9, 136302–136312 (2021). https://doi.org/10.1109/ACCESS.2021.3116027
Zhou, Q., Li, L., Wang, L., Xue, J., Feng, X.: May-happen-in-parallel analysis with static vector clocks. In: Proceedings of the 2018 International Symposium on Code Generation and Optimization, CGO 2018, pp. 228–240. Association for Computing Machinery, New York, NY, USA (2018). https://doi.org/10.1145/3168813
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2025 The Author(s), under exclusive license to Springer Nature Switzerland AG
About this paper
Cite this paper
Liu, B., Joshi, D. (2025). GoGuard: Efficient Static Blocking Bug Detection for Go. In: Giacobazzi, R., Gorla, A. (eds) Static Analysis. SAS 2024. Lecture Notes in Computer Science, vol 14995. Springer, Cham. https://doi.org/10.1007/978-3-031-74776-2_9
Download citation
DOI: https://doi.org/10.1007/978-3-031-74776-2_9
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-031-74775-5
Online ISBN: 978-3-031-74776-2
eBook Packages: Computer ScienceComputer Science (R0)