Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/cmd/gopls: deadlock after deleting file #32368

Closed
muirdm opened this issue May 31, 2019 · 2 comments
Closed

x/tools/cmd/gopls: deadlock after deleting file #32368

muirdm opened this issue May 31, 2019 · 2 comments

Comments

@muirdm
Copy link

@muirdm muirdm commented May 31, 2019

After deleting a file from a package and editing another file in the package I immediately get stuck with "no room in queue". The stack trace (pasted below) shows a goroutine blocking on a wait group at parse.go:92. It appears the surrounding code has a case where it returns without decrementing the wait group, which is probably causing this deadlock. The other side of the deadlock is cache/view.go:299 trying to acquire the view's mutex.

/cc @ianthehat

goroutine profile: total 6
1 @ 0x1030a8f 0x102c25a 0x102b846 0x10bb70b 0x10bdd4a 0x10bdd2b 0x114b8b2 0x1166522 0x11650f8 0x14e260d 0x1513984 0x1513952 0x105d6c1
#	0x102b845	internal/poll.runtime_pollWait+0x55			/usr/local/go/src/runtime/netpoll.go:182
#	0x10bb70a	internal/poll.(*pollDesc).wait+0x9a			/usr/local/go/src/internal/poll/fd_poll_runtime.go:87
#	0x10bdd49	internal/poll.(*pollDesc).waitRead+0x1b9		/usr/local/go/src/internal/poll/fd_poll_runtime.go:92
#	0x10bdd2a	internal/poll.(*FD).Accept+0x19a			/usr/local/go/src/internal/poll/fd_unix.go:384
#	0x114b8b1	net.(*netFD).accept+0x41				/usr/local/go/src/net/fd_unix.go:238
#	0x1166521	net.(*TCPListener).accept+0x31				/usr/local/go/src/net/tcpsock_posix.go:139
#	0x11650f7	net.(*TCPListener).Accept+0x47				/usr/local/go/src/net/tcpsock.go:260
#	0x14e260c	net/http.(*Server).Serve+0x22c				/usr/local/go/src/net/http/server.go:2859
#	0x1513983	net/http.Serve+0x53					/usr/local/go/src/net/http/server.go:2456
#	0x1513951	golang.org/x/tools/internal/lsp/debug.Serve.func1+0x21	/Users/muir/projects/tools/internal/lsp/debug/serve.go:34

1 @ 0x1030a8f 0x1040e09 0x1040ddf 0x1040a89 0x10744f5 0x137f11b 0x137a746 0x137a3a8 0x137d96e 0x137cbba 0x1352e36 0x136a727 0x13749c7 0x105d6c1
#	0x1040a88	sync.runtime_Semacquire+0x38						/usr/local/go/src/runtime/sema.go:56
#	0x10744f4	sync.(*WaitGroup).Wait+0x64						/usr/local/go/src/sync/waitgroup.go:130
#	0x137f11a	golang.org/x/tools/internal/lsp/cache.(*importer).parseFiles+0x24a	/Users/muir/projects/tools/internal/lsp/cache/parse.go:92
#	0x137a745	golang.org/x/tools/internal/lsp/cache.(*importer).typeCheck+0x305	/Users/muir/projects/tools/internal/lsp/cache/check.go:99
#	0x137a3a7	golang.org/x/tools/internal/lsp/cache.(*importer).getPkg+0x2e7		/Users/muir/projects/tools/internal/lsp/cache/check.go:58
#	0x137d96d	golang.org/x/tools/internal/lsp/cache.(*view).loadParseTypecheck+0x30d	/Users/muir/projects/tools/internal/lsp/cache/load.go:45
#	0x137cbb9	golang.org/x/tools/internal/lsp/cache.(*goFile).GetPackage+0x149	/Users/muir/projects/tools/internal/lsp/cache/gofile.go:52
#	0x1352e35	golang.org/x/tools/internal/lsp/source.Diagnostics+0x65			/Users/muir/projects/tools/internal/lsp/source/diagnostics.go:55
#	0x136a726	golang.org/x/tools/internal/lsp.(*Server).Diagnostics+0x3d6		/Users/muir/projects/tools/internal/lsp/diagnostics.go:31
#	0x13749c6	golang.org/x/tools/internal/lsp.(*Server).cacheAndDiagnose.func1+0x66	/Users/muir/projects/tools/internal/lsp/text_synchronization.go:53

1 @ 0x1030a8f 0x1040e09 0x1040ddf 0x1040b7d 0x1073299 0x1383a4d 0x13740cd 0x13743e1 0x1368474 0x1370189 0x118bcec 0x117f85a 0x105d6c1
#	0x1040b7c	sync.runtime_SemacquireMutex+0x3c					/usr/local/go/src/runtime/sema.go:71
#	0x1073298	sync.(*Mutex).Lock+0x108						/usr/local/go/src/sync/mutex.go:134
#	0x1383a4c	golang.org/x/tools/internal/lsp/cache.(*view).GetFile+0x4c		/Users/muir/projects/tools/internal/lsp/cache/view.go:299
#	0x13740cc	golang.org/x/tools/internal/lsp.getSourceFile+0x7c			/Users/muir/projects/tools/internal/lsp/util.go:50
#	0x13743e0	golang.org/x/tools/internal/lsp.getGoFile+0x80				/Users/muir/projects/tools/internal/lsp/util.go:68
#	0x1368473	golang.org/x/tools/internal/lsp.(*Server).completion+0xd3		/Users/muir/projects/tools/internal/lsp/completion.go:21
#	0x1370188	golang.org/x/tools/internal/lsp.(*Server).Completion+0x48		/Users/muir/projects/tools/internal/lsp/server.go:162
#	0x118bceb	golang.org/x/tools/internal/lsp/protocol.serverHandler.func1+0x2bfb	/Users/muir/projects/tools/internal/lsp/protocol/tsserver.go:265
#	0x117f859	golang.org/x/tools/internal/jsonrpc2.(*Conn).Run.func1+0xd9		/Users/muir/projects/tools/internal/jsonrpc2/jsonrpc2.go:276

1 @ 0x104c69e 0x10a54b7 0x10bc4af 0x10bc489 0x10c1ea0 0x10c1e73 0x11779cf 0x117871d 0x1178bc0 0x117e518 0x117e50a 0x117d8ae 0x151b6c0 0x13a1aa7 0x13a08f3 0x15154cc 0x13a1aa7 0x13a08f3 0x1524a5b 0x103069c 0x105d6c1
#	0x104c69d	syscall.syscall+0x2d						/usr/local/go/src/runtime/sys_darwin.go:63
#	0x10a54b6	syscall.read+0x66						/usr/local/go/src/syscall/zsyscall_darwin_amd64.go:1169
#	0x10bc4ae	syscall.Read+0x12e						/usr/local/go/src/syscall/syscall_unix.go:172
#	0x10bc488	internal/poll.(*FD).Read+0x108					/usr/local/go/src/internal/poll/fd_unix.go:165
#	0x10c1e9f	os.(*File).read+0x6f						/usr/local/go/src/os/file_unix.go:263
#	0x10c1e72	os.(*File).Read+0x42						/usr/local/go/src/os/file.go:108
#	0x11779ce	bufio.(*Reader).fill+0x10e					/usr/local/go/src/bufio/bufio.go:100
#	0x117871c	bufio.(*Reader).ReadSlice+0x3c					/usr/local/go/src/bufio/bufio.go:356
#	0x1178bbf	bufio.(*Reader).ReadBytes+0x6f					/usr/local/go/src/bufio/bufio.go:434
#	0x117e517	bufio.(*Reader).ReadString+0x87					/usr/local/go/src/bufio/bufio.go:474
#	0x117e509	golang.org/x/tools/internal/jsonrpc2.(*headerStream).Read+0x79	/Users/muir/projects/tools/internal/jsonrpc2/stream.go:97
#	0x117d8ad	golang.org/x/tools/internal/jsonrpc2.(*Conn).Run+0xed		/Users/muir/projects/tools/internal/jsonrpc2/jsonrpc2.go:281
#	0x151b6bf	golang.org/x/tools/internal/lsp/cmd.(*Serve).Run+0x53f		/Users/muir/projects/tools/internal/lsp/cmd/serve.go:95
#	0x13a1aa6	golang.org/x/tools/internal/tool.Main.func2+0xb6		/Users/muir/projects/tools/internal/tool/tool.go:130
#	0x13a08f2	golang.org/x/tools/internal/tool.Main+0x242			/Users/muir/projects/tools/internal/tool/tool.go:131
#	0x15154cb	golang.org/x/tools/internal/lsp/cmd.(*Application).Run+0x4ab	/Users/muir/projects/tools/internal/lsp/cmd/cmd.go:106
#	0x13a1aa6	golang.org/x/tools/internal/tool.Main.func2+0xb6		/Users/muir/projects/tools/internal/tool/tool.go:130
#	0x13a08f2	golang.org/x/tools/internal/tool.Main+0x242			/Users/muir/projects/tools/internal/tool/tool.go:131
#	0x1524a5a	main.main+0xba							/Users/muir/projects/tools/cmd/gopls/main.go:20
#	0x103069b	runtime.main+0x20b						/usr/local/go/src/runtime/proc.go:200

1 @ 0x104c69e 0x10a54b7 0x10bc4af 0x10bc489 0x114af9f 0x115d509 0x14d8088 0x105d6c1
#	0x104c69d	syscall.syscall+0x2d				/usr/local/go/src/runtime/sys_darwin.go:63
#	0x10a54b6	syscall.read+0x66				/usr/local/go/src/syscall/zsyscall_darwin_amd64.go:1169
#	0x10bc4ae	syscall.Read+0x12e				/usr/local/go/src/syscall/syscall_unix.go:172
#	0x10bc488	internal/poll.(*FD).Read+0x108			/usr/local/go/src/internal/poll/fd_unix.go:165
#	0x114af9e	net.(*netFD).Read+0x4e				/usr/local/go/src/net/fd_unix.go:202
#	0x115d508	net.(*conn).Read+0x68				/usr/local/go/src/net/net.go:177
#	0x14d8087	net/http.(*connReader).backgroundRead+0x57	/usr/local/go/src/net/http/server.go:677

1 @ 0x1399070 0x1398e90 0x1395a60 0x1512206 0x1512c67 0x14def54 0x14e0e56 0x14e2228 0x14ddf11 0x105d6c1
#	0x139906f	runtime/pprof.writeRuntimeProfile+0x8f	/usr/local/go/src/runtime/pprof/pprof.go:708
#	0x1398e8f	runtime/pprof.writeGoroutine+0x9f	/usr/local/go/src/runtime/pprof/pprof.go:670
#	0x1395a5f	runtime/pprof.(*Profile).WriteTo+0x38f	/usr/local/go/src/runtime/pprof/pprof.go:329
#	0x1512205	net/http/pprof.handler.ServeHTTP+0x355	/usr/local/go/src/net/http/pprof/pprof.go:245
#	0x1512c66	net/http/pprof.Index+0x6f6		/usr/local/go/src/net/http/pprof/pprof.go:268
#	0x14def53	net/http.HandlerFunc.ServeHTTP+0x43	/usr/local/go/src/net/http/server.go:1995
#	0x14e0e55	net/http.(*ServeMux).ServeHTTP+0x1d5	/usr/local/go/src/net/http/server.go:2375
#	0x14e2227	net/http.serverHandler.ServeHTTP+0xa7	/usr/local/go/src/net/http/server.go:2774
#	0x14ddf10	net/http.(*conn).serve+0x850		/usr/local/go/src/net/http/server.go:1878
@gopherbot gopherbot added this to the Unreleased milestone May 31, 2019
@gopherbot gopherbot added the gopls label May 31, 2019
@stamblerre
Copy link
Contributor

@stamblerre stamblerre commented May 31, 2019

freeformz pushed a commit to freeformz/tools that referenced this issue May 31, 2019
Edward Muller
Fixes golang/go#32368

There were several returns in this function that could leak both the
wg.Done() and <-ioLimit. This refactors them into defers close to their
counterparts.

Additionally I refactored the function to favor early returns over
nested if statements.
@gopherbot
Copy link

@gopherbot gopherbot commented May 31, 2019

Change https://golang.org/cl/179878 mentions this issue: Fix leaking wg.Done() and <-ioLimit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.