Understanding Concurrency Bugs in Real-World Programs with Kotlin Coroutines

Authors Bob Brockbernd, Nikita Koval, Arie van Deursen , Burcu Kulahcioglu Ozkan



PDF
Thumbnail PDF

File

LIPIcs.ECOOP.2024.8.pdf
  • Filesize: 1.35 MB
  • 20 pages

Document Identifiers

Author Details

Bob Brockbernd
  • Delft University of Technology, The Netherlands
Nikita Koval
  • JetBrains, Amsterdam, The Netherlands
Arie van Deursen
  • Delft University of Technology, The Netherlands
Burcu Kulahcioglu Ozkan
  • Delft University of Technology, The Netherlands

Acknowledgements

We thank our shepherd, Elisa Gonzalez Boix, and anonymous reviewers for their suggestions for improving the paper.

Cite AsGet BibTex

Bob Brockbernd, Nikita Koval, Arie van Deursen, and Burcu Kulahcioglu Ozkan. Understanding Concurrency Bugs in Real-World Programs with Kotlin Coroutines. In 38th European Conference on Object-Oriented Programming (ECOOP 2024). Leibniz International Proceedings in Informatics (LIPIcs), Volume 313, pp. 8:1-8:20, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2024)
https://doi.org/10.4230/LIPIcs.ECOOP.2024.8

Abstract

Kotlin language has recently become prominent for developing both Android and server-side applications. These programs are typically designed to be fast and responsive, with asynchrony and concurrency at their core. To enable developers to write asynchronous and concurrent code safely and concisely, Kotlin provides built-in coroutines support. However, developers unfamiliar with the coroutines concept may write programs with subtle concurrency bugs and face unexpected program behaviors. Besides the traditional concurrency bug patterns, such as data races and deadlocks, these bugs may exhibit patterns related to the coroutine semantics. Understanding these coroutine-specific bug patterns in real-world Kotlin applications is essential in avoiding common mistakes and writing correct programs. In this paper, we present the first study of real-world concurrency bugs related to Kotlin coroutines. We examined 55 concurrency bug cases selected from 7 popular open-source repositories that use Kotlin coroutines, including IntelliJ IDEA, Firefox, and Ktor, and analyzed their bug characteristics and root causes. We identified common bug patterns related to asynchrony and Kotlin’s coroutine semantics, presenting them with their root causes, misconceptions that led to the bugs, and strategies for their automated detection. Overall, this study provides insight into programming with Kotlin coroutines concurrency and its pitfalls, aiming to shed light on common bug patterns and foster further research and development of concurrency analysis tools for Kotlin programs.

Subject Classification

ACM Subject Classification
  • Computing methodologies → Concurrent programming languages
  • Software and its engineering → Software testing and debugging
Keywords
  • Kotlin
  • coroutines
  • concurrency
  • asynchrony
  • software bugs

Metrics

  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    0
    PDF Downloads

References

  1. Sara Abbaspour Asadollah, Daniel Sundmark, Sigrid Eldh, Hans Hansson, and Wasif Afzal. 10 years of research on debugging concurrent and multicore software: a systematic mapping study. Softw. Qual. J., 25(1):49-82, 2017. URL: https://doi.org/10.1007/S11219-015-9301-7.
  2. Automattic. Woocommerce Android app, 2023. URL: https://github.com/shadowsocks/shadowsocks-android.
  3. Automattic. Wordpress for android, 2023. URL: https://github.com/wordpress-mobile/WordPress-Android.
  4. Mehdi Bagherzadeh, Nicholas Fireman, Anas Shawesh, and Raffi Khatchadourian. Actor concurrency bugs: a comprehensive study on symptoms, root causes, API usages, and differences. Proc. ACM Program. Lang., 4(OOPSLA):214:1-214:32, 2020. URL: https://doi.org/10.1145/3428282.
  5. Jeff Boek. Bugfix commit, firefox for android, November 2018. URL: https://github.com/mozilla-mobile/firefox-android/commit/d18bfe9f1bb5f0ed0f85e5fa36cddfaee84b5d47.
  6. Bob Brockbernd. Found bugs per bug type, April 2024. URL: https://github.com/bbrockbernd/kotlin-coroutine-bugs.
  7. Bob Brockbernd. Runblocking inspection implementation, June 2024. URL: https://github.com/JetBrains/intellij-community/commit/ea8296d53925ec87ddbee66f37412793d3fbdb14.
  8. Milind Chabbi and Murali Krishna Ramanathan. A study of real-world data races in Golang. In Ranjit Jhala and Isil Dillig, editors, PLDI '22: 43rd ACM SIGPLAN International Conference on Programming Language Design and Implementation, San Diego, CA, USA, June 13 - 17, 2022, pages 474-489. ACM, 2022. URL: https://doi.org/10.1145/3519939.3523720.
  9. Yi-An Chen and Yi-Ping You. Structured concurrency: A review. In Workshop Proceedings of the 51st International Conference on Parallel Processing, ICPP Workshops 2022, Bordeaux, France, 29 August 2022 - 1 September 2022, pages 16:1-16:8. ACM, 2022. URL: https://doi.org/10.1145/3547276.3548519.
  10. Sam Cooper. How I fell in Kotlin’s runblocking deadlock trap, and how you can avoid it, October 2023. URL: https://betterprogramming.pub/how-i-fell-in-kotlins-runblocking-deadlock-trap-and-how-you-can-avoid-it-db9e7c4909f1.
  11. Sam Cooper. The silent killer that’s crashing your coroutines, February 2023. URL: https://medium.com/better-programming/the-silent-killer-thats-crashing-your-coroutines-9171d1e8f79b.
  12. Ana Lúcia de Moura and Roberto Ierusalimschy. Revisiting coroutines. ACM Trans. Program. Lang. Syst., 31(2):6:1-6:31, 2009. URL: https://doi.org/10.1145/1462166.1462167.
  13. Nicolas Dilley and Julien Lange. Automated verification of go programs via bounded model checking. In 36th IEEE/ACM International Conference on Automated Software Engineering, ASE 2021, Melbourne, Australia, November 15-19, 2021, pages 1016-1027. IEEE, 2021. URL: https://doi.org/10.1109/ASE51524.2021.9678571.
  14. Roman Elizarov, Mikhail A. Belyaev, Marat Akhin, and Ilmir Usmanov. Kotlin coroutines: design and implementation. In Wolfgang De Meuter and Elisa L. A. Baniassad, editors, Onward! 2021: Proceedings of the 2021 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software, Virtual Event / Chicago, IL, USA, October 20-22, 2021, pages 68-84. ACM, 2021. URL: https://doi.org/10.1145/3486607.3486751.
  15. Rui Gu, Guoliang Jin, Linhai Song, Linjie Zhu, and Shan Lu. What change history tells us about thread synchronization. In Elisabetta Di Nitto, Mark Harman, and Patrick Heymans, editors, Proceedings of the 2015 10th Joint Meeting on Foundations of Software Engineering, ESEC/FSE 2015, Bergamo, Italy, August 30 - September 4, 2015, pages 426-438. ACM, 2015. URL: https://doi.org/10.1145/2786805.2786815.
  16. Brandon Hedden and Xinghui Zhao. A comprehensive study on bugs in actor systems. In Proceedings of the 47th International Conference on Parallel Processing, ICPP 2018, Eugene, OR, USA, August 13-16, 2018, pages 56:1-56:9. ACM, 2018. URL: https://doi.org/10.1145/3225058.3225139.
  17. JetBrains. Intellij idea community edition, 2023. URL: https://github.com/JetBrains/intellij-community.
  18. JetBrains. Ktor, 2023. URL: https://github.com/ktorio/ktor.
  19. Nikita Koval, Alexander Fedorov, Maria Sokolova, Dmitry Tsitelov, and Dan Alistarh. Lincheck: A practical framework for testing concurrent data structures on JVM. In Constantin Enea and Akash Lal, editors, Computer Aided Verification - 35th International Conference, CAV 2023, Paris, France, July 17-22, 2023, Proceedings, Part I, volume 13964 of Lecture Notes in Computer Science, pages 156-169. Springer, 2023. URL: https://doi.org/10.1007/978-3-031-37706-8_8.
  20. Ziheng Liu, Shihao Xia, Yu Liang, Linhai Song, and Hong Hu. Who goes first? detecting go concurrency bugs via message reordering. In Babak Falsafi, Michael Ferdman, Shan Lu, and Thomas F. Wenisch, editors, ASPLOS '22: 27th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Lausanne, Switzerland, 28 February 2022 - 4 March 2022, pages 888-902. ACM, 2022. URL: https://doi.org/10.1145/3503222.3507753.
  21. Ziheng Liu, Shuofei Zhu, Boqin Qin, Hao Chen, and Linhai Song. Automatically detecting and fixing concurrency bugs in go software systems. In Tim Sherwood, Emery D. Berger, and Christos Kozyrakis, editors, ASPLOS '21: 26th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Virtual Event, USA, April 19-23, 2021, pages 616-629. ACM, 2021. URL: https://doi.org/10.1145/3445814.3446756.
  22. Carmen Torres Lopez, Stefan Marr, Elisa Gonzalez Boix, and Hanspeter Mössenböck. A study of concurrency bugs and advanced development support for actor-based programs. In Alessandro Ricci and Philipp Haller, editors, Programming with Actors - State-of-the-Art and Research Perspectives, volume 10789 of Lecture Notes in Computer Science, pages 155-185. Springer, 2018. URL: https://doi.org/10.1007/978-3-030-00302-9_6.
  23. Shan Lu, Soyeon Park, Eunsoo Seo, and Yuanyuan Zhou. Learning from mistakes: a comprehensive study on real world concurrency bug characteristics. In Susan J. Eggers and James R. Larus, editors, Proceedings of the 13th International Conference on Architectural Support for Programming Languages and Operating Systems, ASPLOS 2008, Seattle, WA, USA, March 1-5, 2008, pages 329-339. ACM, 2008. URL: https://doi.org/10.1145/1346281.1346323.
  24. Sergey Mashkov. Bugfix commit, ktor, October 2020. URL: https://github.com/ktorio/ktor/commit/7dfa6d9f1650430738e76cba165eb3529687be3c.
  25. Mozilla. Firefox for android, 2023. URL: https://github.com/mozilla-mobile/firefox-android.
  26. Semih Okur, David L. Hartveld, Danny Dig, and Arie van Deursen. A study and toolkit for asynchronous programming in c#. In Pankaj Jalote, Lionel C. Briand, and André van der Hoek, editors, 36th International Conference on Software Engineering, ICSE '14, Hyderabad, India - May 31 - June 07, 2014, pages 1117-1127. ACM, 2014. URL: https://doi.org/10.1145/2568225.2568309.
  27. Daniil Ovchinnikov. Runblocking should let go of CPU token before parking the thread, December 2023. URL: https://github.com/Kotlin/kotlinx.coroutines/issues/3983.
  28. Ondrej Ruttkay. Bugfix commit, woocommerce android app, January 2021. URL: https://github.com/woocommerce/woocommerce-android/commit/6156420791b1e78067cd5dacbe5a15d0cc24979d.
  29. Anton Spaans. Provide a runcatching that does not handle a cancellationexception but re-throws it instead, February 2020. URL: https://github.com/Kotlin/kotlinx.coroutines/issues/1814.
  30. Quentin Stiévenart and Magnus Madsen. Fuzzing channel-based concurrency runtimes using types and effects. Proc. ACM Program. Lang., 4(OOPSLA):186:1-186:27, 2020. URL: https://doi.org/10.1145/3428254.
  31. Mygod Studio. Shadowsocks for android, 2023. URL: https://github.com/shadowsocks/shadowsocks-android.
  32. Petr Surkov. Bugfix commit, woocommerce android app, March 2024. URL: https://github.com/woocommerce/woocommerce-android/commit/5dbb3b1834f67f097be7db96cab04c3ca99d7294.
  33. Don Syme, Tomas Petricek, and Dmitry Lomov. The f# asynchronous programming model. In Ricardo Rocha and John Launchbury, editors, Practical Aspects of Declarative Languages - 13th International Symposium, PADL 2011, Austin, TX, USA, January 24-25, 2011. Proceedings, volume 6539 of Lecture Notes in Computer Science, pages 175-189. Springer, 2011. URL: https://doi.org/10.1007/978-3-642-18378-2_15.
  34. Martin Sústrik. Structured concurrency, February 2016. URL: https://250bpm.com/blog:71/.
  35. Tachiyomiorg. Tachiyomi, 2023. URL: https://github.com/tachiyomiorg/tachiyomi.
  36. Saeed Taheri and Ganesh Gopalakrishnan. Automated dynamic concurrency analysis for go, 2021. URL: https://arxiv.org/abs/2105.11064.
  37. Andrew Troelsen and Andy Olsen. Pro C# 5.0 and the. NET 4.5 Framework, volume 6. Springer, 2012. Google Scholar
  38. Tengfei Tu, Xiaoyu Liu, Linhai Song, and Yiying Zhang. Understanding real-world concurrency bugs in go. In Iris Bahar, Maurice Herlihy, Emmett Witchel, and Alvin R. Lebeck, editors, Proceedings of the Twenty-Fourth International Conference on Architectural Support for Programming Languages and Operating Systems, ASPLOS 2019, Providence, RI, USA, April 13-17, 2019, pages 865-878. ACM, 2019. URL: https://doi.org/10.1145/3297858.3304069.
  39. Oskar Haarklou Veileborg, Georgian-Vlad Saioc, and Anders Møller. Detecting blocking errors in Go programs using localized abstract interpretation. In 37th IEEE/ACM International Conference on Automated Software Engineering, ASE 2022, Rochester, MI, USA, October 10-14, 2022, pages 32:1-32:12. ACM, 2022. URL: https://doi.org/10.1145/3551349.3561154.
  40. Jie Wang, Wensheng Dou, Yu Gao, Chushu Gao, Feng Qin, Kang Yin, and Jun Wei. A comprehensive study on real world concurrency bugs in node.js. In Grigore Rosu, Massimiliano Di Penta, and Tien N. Nguyen, editors, Proceedings of the 32nd IEEE/ACM International Conference on Automated Software Engineering, ASE 2017, Urbana, IL, USA, October 30 - November 03, 2017, pages 520-531. IEEE Computer Society, 2017. URL: https://doi.org/10.1109/ASE.2017.8115663.
Questions / Remarks / Feedback
X

Feedback for Dagstuhl Publishing


Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail