13

I am debugging a program written in go via Goland. In the debugger, I can choose between different goroutines that are running. I found alongside my goroutines there is a lot of other goroutines named runtime.gopark and I suspect these are other threads waiting in the thread pool for a job. However, I couldn't find any answer online. Is that so? If not, what is it actually doing?

P.S. Here is a photo of the incident:

enter image description here

5
  • 2
    Refer to the source code for runtime.gopark. The function has documentation just above its definition.
    – jkr
    May 18, 2020 at 2:45
  • A direct link to the source code might help, but be aware that the line number in this link will eventually be wrong.
    – torek
    May 18, 2020 at 3:05
  • 1
    Thank you. I had seen that but since I'm not very familiar with go's source code I was hoping someone more familiar might help. I had got my guess from this comment.
    – Bat
    May 18, 2020 at 3:23
  • 2
    It might be more helpful to note that whenever a goroutine is waiting to send or receive data on a channel, it will be in gopark. That's not the only reason, but it's a pretty likely one.
    – torek
    May 18, 2020 at 5:46
  • 2
    Goroutines don't have names. Their only identity is a number (67 in your example). runtime.gopark is the name of a function that the goroutine happens to be executing. May 18, 2020 at 7:11

1 Answer 1

14

Goroutines are not named. "runtime.gopark" is the package/function where the execution was at the time the debugger stopped the process and took the snapshot of the code execution.

For "runtime.gopark" in particular, this means that the goroutines are temporarily "on hold", paused by the runtime scheduler.

If you wish to get a better insight into the application, and name the goroutines, then you can use a recent version fo the IDE, like 2020.1.2 (or newer), and annotate the code like described in this article.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.