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

Cancel file operations from opening an editor when closing it #57585

Open
solesensei opened this issue Aug 30, 2018 · 14 comments
Open

Cancel file operations from opening an editor when closing it #57585

solesensei opened this issue Aug 30, 2018 · 14 comments
Labels
feature-request Request for new features or functionality file-io File I/O freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues keep Issues we should not close as out of scope
Milestone

Comments

@solesensei
Copy link

Issue Type: Bug

Found a bug.
When you clicked to open huge file, for ex. 1.5 GB txt, and then immediately closed it - VS Code will try to open it anyway, RAM will be overflow, and Studio crashes.

VS Code version: Code 1.26.1 (493869e, 2018-08-16T18:38:57.434Z)
OS version: Windows_NT x64 10.0.17134

@solesensei solesensei changed the title Huge files openning bug Crashes when opens Huge Files [bug] Aug 30, 2018
@alexdima alexdima assigned rebornix and unassigned alexdima Aug 31, 2018
@alexdima alexdima added the editor-textbuffer Editor text buffer label Aug 31, 2018
@rebornix rebornix added the bug Issue identified by VS Code Team member as probable bug label Sep 4, 2018
@rebornix
Copy link
Member

rebornix commented Sep 6, 2018

@solesensei do you still run into this issue when you run code --max-memory=4096?

@rebornix rebornix added under-discussion Issue is under discussion for relevance, priority, approach info-needed Issue requires more information from poster and removed bug Issue identified by VS Code Team member as probable bug labels Sep 6, 2018
@solesensei
Copy link
Author

@rebornix no, 4096 is okay for huge files, i talk about opening process, i have no needs in opening that file.

For me problem is:
when i opened huge file (115m lines), and then clicked close - vs code was continuing reading from my drive in background and overloading RAM. Reading process wasn't killed.

@solesensei
Copy link
Author

solesensei commented Sep 7, 2018

@rebornix
i think that reading process will be closed only after opening whole file in background (=loaded it in RAM)

@rebornix
Copy link
Member

rebornix commented Sep 7, 2018

@solesensei thanks for helping nail down the root cause ;)

@rebornix rebornix added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster under-discussion Issue is under discussion for relevance, priority, approach labels Sep 7, 2018
@rebornix
Copy link
Member

@bpasero may I have some help from your Electron expertise?

@rebornix
Copy link
Member

Unluckily I can't reproduce this issue on my Windows box.

@bpasero
Copy link
Member

bpasero commented Sep 11, 2018

We are reading the file async and not sync so I would think that closing VSCode stops node.js from reading the file but if that is not true the only fix I can see is pushing down a cancellation token all the way (which seems like a workaround for node.js doing the right thing though).

@rebornix rebornix changed the title Crashes when opens Huge Files [bug] Crashes when closing the editor when it's opening Huge Files [bug] Oct 23, 2019
@rebornix
Copy link
Member

By reading https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback and IMHO the potential fix is sending AbortSignal

const controller = new AbortController();
const signal = controller.signal;
fs.readFile(fileInfo[0].name, { signal }, (err, buf) => {
  // ...
});
// When you want to abort the request
controller.abort();

Though I'm not sure if it will really kill the OS process as it's OS dependent. There isn't anything we can do in the text buffer so leave to @bpasero or @deepak1556 to decide if we want to have any fix for it.;

@rebornix rebornix removed their assignment Nov 12, 2020
@rebornix rebornix added file-io File I/O and removed editor-textbuffer Editor text buffer labels Nov 12, 2020
@bpasero bpasero added the *out-of-scope Posted issue is not in scope of VS Code label Nov 12, 2020
@bpasero
Copy link
Member

bpasero commented Nov 12, 2020

This requires cancellation support on the level of the IFileSystemProvider but I am not sure it is worth pushing for it...

//cc @jrieken

@bpasero bpasero changed the title Crashes when closing the editor when it's opening Huge Files [bug] Allow to cancel file read operations Mar 31, 2022
@bpasero bpasero added feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug *out-of-scope Posted issue is not in scope of VS Code labels Mar 31, 2022
@bpasero bpasero added this to the Backlog milestone Mar 31, 2022
@bpasero bpasero removed their assignment Mar 31, 2022
@bpasero bpasero reopened this Mar 31, 2022
@bpasero bpasero changed the title Allow to cancel file read operations Allow to cancel file operations (such as reading large files) Mar 31, 2022
@bpasero bpasero changed the title Allow to cancel file operations (such as reading large files) Allow to cancel file operations either by closing the editor or via setting Apr 6, 2022
@bpasero
Copy link
Member

bpasero commented Apr 6, 2022

Updated the title from the duplicate #146912. If we could introduce a setting for the maximum file size a user can open, we should use that information here:

const fileStat = await statPromise;

To cancel the reading and throw an error so that upstream component can show a generic editor.

@bpasero bpasero changed the title Allow to cancel file operations either by closing the editor or via setting Cancel file operations from opening an editor when closing it Dec 6, 2022
@bpasero bpasero added freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues keep Issues we should not close as out of scope labels Dec 6, 2022
@chickenSandwich
Copy link

This is a big issue for me because I am creating JSON files that have binary blobs that are large. If I click on the file in Explorer the editor will try to preview the file. There is no way to cancel the process of trying to preview/open the file and VSCode eventually displays a dialog asking if I want to close the editor or continue waiting. I cannot open the Developer Tools or the Process Explorer to terminate the tab that is trying to preview/open the file. I have waited for up to 30 minutes, and the file never finishes and the editor is unusable.
The worst part is that when you re-open that folder in VSCode, the same process repeats. The only way that I have been able to get back to work is by deleting the workspaceStorage folder (/home/user/.config/Code/User/workspaceStorage).

It would be nice if I could cancel/abort the preview/open process.

@bpasero
Copy link
Member

bpasero commented Mar 7, 2024

The setting workbench.editorLargeFileConfirmation will help here. Set it to a lower value to match the file sizes you encounter this with and editors will not just open until you confirm.

@chickenSandwich
Copy link

The setting workbench.editorLargeFileConfirmation will help here. Set it to a lower value to match the file sizes you encounter this with and editors will not just open until you confirm.

Thank-you. I had already changed that setting to save myself the trouble from this issue, however, I feel that it would be a valuable addition to VSCode to allow for the cancellation of a long running preview/open process.

@johnyv276
Copy link

this setting doesn't help on custom editors
I opened an issue on the topic at the extension vscode-parquet-viewer
look at the response from the extonsion's dev
dvirtz/vscode-parquet-viewer#144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality file-io File I/O freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues keep Issues we should not close as out of scope
Projects
None yet
Development

No branches or pull requests

7 participants
@rebornix @bpasero @chickenSandwich @alexdima @solesensei @johnyv276 and others