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

Grammars shouldn't be able to freeze VS Code #89916

Closed
alexr00 opened this issue Feb 3, 2020 · 1 comment
Closed

Grammars shouldn't be able to freeze VS Code #89916

alexr00 opened this issue Feb 3, 2020 · 1 comment
Assignees

Comments

@alexr00
Copy link
Member

alexr00 commented Feb 3, 2020

I often get reports of hangs that are caused by a grammar. It would be better if we didn't force a restart of VS Code every time this happens.

From #89846

instead of the current "not responding, would you like to restart" message, have something like "The is not responding. Would you like to view this file in plain text mode instead? "

@alexdima
Copy link
Member

alexdima commented Feb 3, 2020

This is a good suggestion. Here is the entire picture:

  • the message "not responding, would you like to restart" is a generic message shown by the main process when a renderer process stops responding. That can be for any number of reasons, one of which is runaway regular expressions.
  • tokenization is currently implemented on the main thread / UI thread in the renderers and it works with a custom regex engine, oniguruma. Oniguruma is written in C++ and we end up calling into that library. In certain cases, with certain inputs and regular expressions, it takes oniguruma a very very long time (minutes, or hours) to return. This situation is called runaway regular expresions / catastrophic backtracking.
  • unfortunately, oniguruma does not provide currently a mechanism to terminate the matching after X amount of time or after X amount of backtrackings, so we cannot call it differently.
  • the only way I can think of to workaround this is to load up oniguruma on a separate thread (not the UI thread). But there are difficulties with this because tokens are needed synchronously in certain cases while typing. This is discussed/planned in Tokenization overhaul #77140

I share the frustration and I don't think a grammar should end up hanging VS Code, but I suggest we continue tracking #77140

Also, in any case, regardless of vs code hanging or not, the regex must be rewritten. This is ultimately a mistake in the grammar. Regexes which lead to catastrophic backtracking are poorly written regexes and must be rewritten.

@alexdima alexdima closed this as completed Feb 3, 2020
@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 19, 2020
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