11

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

Bat
  • 771
  • 11
  • 29
  • 2
    Refer to the source code for `runtime.gopark`. The function has documentation just above its definition. – jkr May 18 '20 at 02:45
  • A [direct link to the source code](https://golang.org/src/runtime/proc.go#L279) might help, but be aware that the line number in this link will eventually be wrong. – torek May 18 '20 at 03: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 '20 at 03: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 '20 at 05: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. – Jonathan Hall May 18 '20 at 07:11

1 Answers1

13

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
dlsniper
  • 7,188
  • 1
  • 35
  • 44