Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

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

Open
dianedanlai opened this issue Aug 1, 2018 · 2 comments

Comments

@dianedanlai
Copy link

dianedanlai commented Aug 1, 2018

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.

@keegancsmith
Copy link
Member

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.

@dianedanlai
Copy link
Author

dianedanlai commented Aug 7, 2018

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!

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

No branches or pull requests

2 participants