Skip to content

Suppress console.log & others inside the TS Server runtime so that language service plugins don't accidentally use them and kill the server #32668

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

Merged
merged 2 commits into from
Aug 8, 2019

Conversation

orta
Copy link
Contributor

@orta orta commented Aug 1, 2019

Fixes #31209 (where most of the discussion is)

This should probably hold till 3.7

…guage service plugins don't accidentally use them and kill the server - fixes microsoft#31209
@weswigham
Copy link
Member

@RyanCavanaugh would it be possible to just use a private fd (spawning a process with extra pipes established is pretty easy in node) rather than stdout in most tsserver environments? We already use a socket for events... it should be a change to server.ts to not always make the readline instance from process.stdin and process.stdout.

// the log. This is so that language service plugins which use
// console.log don't break the message passing between tsserver
// and the client
console.log = (msg) => logger.msg(msg, Msg.Info);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log/warn/error are normally variadic in node, so would it make sense to do something with all ...args in this replacement function? We'd be less likely to lose important information if a plugin passed multiple things to one log call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the logger accepts variadic args - we can pass the array joined as a string if args.length is greater than 1 though.

@orta
Copy link
Contributor Author

orta commented Aug 6, 2019

We chatted about this and the idea of using a private file descriptor for tsserver comms would be a good move, but that requires all tsserver editors making changes to handle that instead of stdin/stdout - so this should be a good enough for now.

@orta orta merged commit b70f894 into microsoft:master Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TSServer: RangeError: Index out of range, exits with code: 134
3 participants