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

[json] Request textDocument/* failed with message: Cannot read property 'version' of undefined #39344

Closed
code-d opened this issue Nov 30, 2017 · 22 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug json JSON support issues verified Verification succeeded
Milestone

Comments

@code-d
Copy link

code-d commented Nov 30, 2017

Output of "JSON Language Server" always show following error:

[Error - 09:34:46] Request textDocument/hover failed.
  Message: Request textDocument/hover failed with message: Cannot read property 'version' of undefined
  Code: -32603 
[Error - 09:45:08] Request textDocument/completion failed.
  Message: Request textDocument/completion failed with message: Cannot read property 'version' of undefined
  Code: -32603 
  • VSCode Version: Code 1.18.1 (929bacb, 2017-11-16T18:23:26.125Z)
  • OS Version: Darwin x64 17.2.0
  • Extensions: none

Steps to Reproduce:

  1. open any *.json file
    2a. double-click anywhere in the document
    2b. ctrl+space
@jrieken jrieken assigned dbaeumer and unassigned jrieken Dec 4, 2017
@dbaeumer dbaeumer assigned aeschli and unassigned dbaeumer Dec 4, 2017
@dbaeumer dbaeumer added the json JSON support issues label Dec 4, 2017
@aeschli
Copy link
Contributor

aeschli commented Dec 4, 2017

@code-d I'm not able to reproduce.

Can you add the following setting:

  • "json.trace.server": "verbose",

  • open the output view, go to the 'JSON language server tab'
    image

  • reload VSCode (command reload windows)

  • open the problematic file

  • send me the content of the `JSON language server' tab

@aeschli aeschli added the info-needed Issue requires more information from poster label Dec 4, 2017
@code-d
Copy link
Author

code-d commented Dec 6, 2017

@aeschli from my colleagues (i can't reproduce the error myself):
win.txt
mac.txt

@aeschli
Copy link
Contributor

aeschli commented Dec 6, 2017

@code-d Thanks a lot!

What's strange is that there is no notification 'textDocument/didOpen' for pc-boss-frontend/typings.json sent.

  • can you confirm that when you restart, that file is open in the editor
  • what does the editor status bar show as mode? 'JSON'?
  • is there anything special with this file, is it excluded e.g. with the "files.exclude" settings

@dbaeumer Assigning to you, looks like an issue in the language client.

@aeschli aeschli assigned dbaeumer and unassigned aeschli Dec 6, 2017
@dbaeumer
Copy link
Member

dbaeumer commented Dec 6, 2017

@aeschli are you sure: the trace shows a hover request for tsconfig.json. Not sure who is triggering this. The protocol states that the server can receive requests for files that are not open in the editor. So the request is in principal valid.

@code-d Would be cool to know if the file tsconfig.json is open in the editor when this happens.

@aeschli assigning you as well since this might be a problem of the JSON language server as well.

@dbaeumer
Copy link
Member

dbaeumer commented Dec 6, 2017

@code-d can you reproduce this with all extensions disabled. E.g start code form a terminal with --disable-extensions

@code-d
Copy link
Author

code-d commented Dec 7, 2017

@dbaeumer tried run from terminal with code --disable-extensions and the issue remains...
@aeschli @dbaeumer

  • it happens when *.json file is open in the editor.
  • status bar shows 'JSON'.
  • all *.json files are valid and nothing special.
    trace.txt
    trace2.txt

@code-d
Copy link
Author

code-d commented Dec 7, 2017

hi, after hard debugging, i think i've found the cause of the issue:
the issue related to json.schemastore.org
sometimes response data from http://json.schemastore.org are malformed. (maybe its my country's network env problem...)
malformed-json-schema-reponse

my temporary workaround:
edit /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json/server/out/jsonServerMain.js
line#99~103

    var headers = { 'Accept-Encoding': 'gzip, deflate' };
    return request_light_1.xhr({ url: uri, followRedirects: 5, headers: headers }).then(function (response) {
        return response.responseText;
    }, function (error) {
        return Promise.reject(error.responseText || request_light_1.getErrorStatusDescription(error.status) || error.toString());
    });

change to

    var headers = { }; //if use gzip, the corrupted xhr response may never finish??
    return request_light_1.xhr({ url: uri, followRedirects: 5, headers: headers }).then(function (response) {
        // try {
            JSON.parse(response.responseText); //try parse now, throw error if response data is corrupted
        // } catch (e) {
            // throw e;
        // }
        return response.responseText;
    }, function (error) {
        return Promise.reject(error.responseText || request_light_1.getErrorStatusDescription(error.status) || error.toString());
    });

@dbaeumer
Copy link
Member

dbaeumer commented Dec 7, 2017

The second trace has a hint why this is happening. For some reason the JSON server crashes and is not restarted correctly. Would be good to know why it is crashing / the connection is closed

[Error - 12:02:04] Request textDocument/hover failed.
Error: Connection got disposed.
	at Object.dispose (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json/node_modules/vscode-jsonrpc/lib/main.js:819:25)
	at Object.dispose (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json/node_modules/vscode-languageclient/lib/client.js:57:35)
	at LanguageClient.handleConnectionClosed (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json/node_modules/vscode-languageclient/lib/client.js:1864:38)
	at LanguageClient.handleConnectionClosed (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json/node_modules/vscode-languageclient/lib/main.js:87:15)
	at closeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json/node_modules/vscode-languageclient/lib/client.js:1852:18)
	at CallbackList.invoke (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json/node_modules/vscode-jsonrpc/lib/events.js:71:39)
	at Emitter.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json/node_modules/vscode-jsonrpc/lib/events.js:135:36)
	at closeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json/node_modules/vscode-jsonrpc/lib/main.js:215:26)
	at CallbackList.invoke (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json/node_modules/vscode-jsonrpc/lib/events.js:71:39)
	at Emitter.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json/node_modules/vscode-jsonrpc/lib/events.js:135:36)

@dbaeumer
Copy link
Member

dbaeumer commented Dec 7, 2017

@code-d very nice analysis. Thanks for the hard debugging. This explains why the server is crashing and not restarting.

@dbaeumer
Copy link
Member

dbaeumer commented Dec 7, 2017

@aeschli this means even if the LSP client would restart the server it would crash 5 times and then would be dead as well.

Open microsoft/vscode-languageserver-node#286 to handle this better in the client. However there is additional work in the JSON server necessary. Leaving this work in this item.

@dbaeumer dbaeumer removed the info-needed Issue requires more information from poster label Dec 7, 2017
@dbaeumer dbaeumer assigned aeschli and unassigned dbaeumer Dec 7, 2017
@dbaeumer
Copy link
Member

dbaeumer commented Dec 7, 2017

Publish 4.0.0-next.3 of the client which contains a fix for the exception handling. But please note that this version will not fix the underlying problem of the server crashing.

@aeschli
Copy link
Contributor

aeschli commented Dec 7, 2017

@dbaeumer Any chance the error message sent to the client (Request textDocument/completion failed with message: Cannot read property 'version' of undefined Code: -32603) could include the stacktrace?

@dbaeumer
Copy link
Member

dbaeumer commented Dec 7, 2017

@aeschli Currently I implement the JSON RPC spec (http://www.jsonrpc.org/specification#error_object). We could add a stack to the data property or add an additional property. But both would be LSP specific and clients would need to know about this.

@aeschli
Copy link
Contributor

aeschli commented Dec 18, 2017

@code-d Thanks for your investigations and findings.
I added code to catch all errors and log the full stack trace in the JSON output to 1.19. It should be no longer be possible to crash the whole server with a malformed response.

  • Can you try again in 1.19 (just released)?
  • Can you send me the content one of the malformed response?

@aeschli aeschli changed the title Request textDocument/* failed with message: Cannot read property 'version' of undefined [json] Request textDocument/* failed with message: Cannot read property 'version' of undefined Dec 19, 2017
@aeschli aeschli added this to the December 2017/January 2018 milestone Dec 19, 2017
@aeschli aeschli added the bug Issue identified by VS Code Team member as probable bug label Dec 19, 2017
@code-d
Copy link
Author

code-d commented Dec 20, 2017

@aeschli still receive the error message in 1.19

trace-1.19.txt
malformed-tsconfig.json.txt

@code-d
Copy link
Author

code-d commented Dec 20, 2017

@aeschli hi, i finally found out the issue is related to your 'request-light' module:
when gzip encoding is used, and the response is malformed/corrupted, it will crash whole node process. so Promise.catch is not work
see Response stream need error handling #2

@aeschli
Copy link
Contributor

aeschli commented Dec 21, 2017

Thanks a lot @code-d, that's a great help. I made a fix, this should be in tomorrows build. It would be great if you can verify if the fix works for you.

@vscodebot vscodebot bot locked and limited conversation to collaborators Feb 4, 2018
@aeschli
Copy link
Contributor

aeschli commented Feb 5, 2018

@code-d Were you able to verify that this fix in one of the latest insider builds?

@ramya-rao-a
Copy link
Contributor

@aeschli How do you recommend we go around verifying this?

@octref
Copy link
Contributor

octref commented Feb 5, 2018

@aeschli The conversation is locked...Even if @code-d wanted he could not comment.

@microsoft microsoft unlocked this conversation Feb 5, 2018
@code-d
Copy link
Author

code-d commented Feb 6, 2018

@aeschli hi, i've tested. the error is gone.. i think it has been fixed

ps. strictly speaking: i can't verify the case of malformed schema/response data, because the responses from json.schemastore.org are all valid for the time being.

@aeschli aeschli added the verified Verification succeeded label Feb 7, 2018
@aeschli
Copy link
Contributor

aeschli commented Feb 7, 2018

Thanks @code-d, that's good enough, we mark it as verified.

@vscodebot vscodebot bot locked and limited conversation to collaborators Feb 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug json JSON support issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants