From 3941af1d02e85e5c316d72ac4077ff13cdaa2e08 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Wed, 21 Jul 2021 10:26:40 -0500 Subject: [PATCH] service/dap: limit the number of goroutines to return from a threads request (#2595) 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 --- service/dap/server.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/service/dap/server.go b/service/dap/server.go index f122aa21..34c8a579 100644 --- a/service/dap/server.go +++ b/service/dap/server.go @@ -191,6 +191,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 @@ -1456,7 +1458,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: @@ -1469,6 +1471,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