go-langserver icon indicating copy to clipboard operation
go-langserver copied to clipboard

Get error of "Header must provide a Content-Length property" and then go language server shut down.

Open dianedanlai opened this issue 7 years ago • 2 comments

I am working on the integration of a editor and go language server. In rare cases, I can see error "Header must provide a Content-Length property" and then go language server shut down.

I saw in the output of go language server, its response is malformed like below, which causes the client side cannot parse the response correctly.

screen shot 2018-08-01 at 10 11 45 am

The error above is from gocode and the "invalid memory address or nil pointer dereference" it refers to is in function fixup_packages. In the first if statement, pcache[path] is nil, but it tries to access its defalias.

func fixup_packages(filescope *scope, pkgs []package_import, pcache package_cache) {
	for _, p := range pkgs {
		path, alias := p.abspath, p.alias
		if alias == "" {
			alias = pcache[path].defalias
		}
		// skip packages that will be merged to the package scope
		if alias == "." {
			continue
		}
		filescope.replace_decl(alias, pcache[path].main)
	}
}

One thing I found is in gocode, if something gets wrong, sometimes print_backtrace(err) is called to write panic and related information to standard output, which may pollutes the response. Related file: https://github.com/nsf/gocode/blob/416643789f088aa5077f667cecde7f966131f6be/autocompletecontext.go https://github.com/nsf/gocode/blob/d09cef6327ed848a446636a857cd851dc7e63d19/utils.go#L184

It is not easy for me to reproduce this problem which makes debugging difficult. If you have more knowledge of gocode and go language server, could you please let me know if my guess is correct.

dianedanlai avatar Aug 01 '18 19:08 dianedanlai

Nice catch with both the upstream issue in gocode and it printing to stderr. We actually need to switch to https://github.com/mdempsky/gocode anyways. We probably need to work out a way to more cleanly integrate gocode as it is. Right now it is manually vendored in and modified, and as such it makes it harder to integrate upstream changes.

keegancsmith avatar Aug 03 '18 10:08 keegancsmith

Thanks for the reply. I think the gocode writes errors directly into stdout instead of stderr, it uses fmt.Printf to write errors and the response write to stdout also. I would like to know if you have a ETA for the integration of new gocode? Thanks!

dianedanlai avatar Aug 07 '18 21:08 dianedanlai