Skip to content

Commit

Permalink
service/dap: limit the number of goroutines to return from a threads …
Browse files Browse the repository at this point in the history
…request

This adds a cap and a log message if there are many goroutines. This will help
prevent the debugger from freezing, but does not yet address making sure the
interesting goroutines are the ones that are returned.

Updates golang/vscode-go#129
  • Loading branch information
suzmue committed Jul 16, 2021
1 parent f86ed67 commit 46b7f3f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ const (
// what is presented. A common use case of a call injection is to
// stringify complex data conveniently.
maxStringLenInCallRetVars = 1 << 10 // 1024
// Max number of goroutines that we will return.
maxGoroutines = 1 << 10
)

// NewServer creates a new DAP Server. It takes an opened Listener
Expand Down Expand Up @@ -1357,7 +1359,7 @@ func (s *Server) onThreadsRequest(request *dap.ThreadsRequest) {
return
}

gs, _, err := s.debugger.Goroutines(0, 0)
gs, next, err := s.debugger.Goroutines(0, maxGoroutines)
if err != nil {
switch err.(type) {
case proc.ErrProcessExited:
Expand All @@ -1370,6 +1372,10 @@ func (s *Server) onThreadsRequest(request *dap.ThreadsRequest) {
return
}

if next >= 0 {
s.logToConsole(fmt.Sprintf("too many goroutines, only loaded %d", len(gs)))
}

threads := make([]dap.Thread, len(gs))
if len(threads) == 0 {
// Depending on the debug session stage, goroutines information
Expand Down

0 comments on commit 46b7f3f

Please sign in to comment.