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

opening large or binary files #8152

Merged
merged 4 commits into from
Aug 3, 2020
Merged

Conversation

akosyakov
Copy link
Member

@akosyakov akosyakov commented Jul 8, 2020

What it does

fix #3859, fix #4731

Important: the goal of this PR is to prevent a user to crash the browser tab, it does not aim to improve performance in the electron case. See also: #8152 (comment)

  • fix #7269: complete support vscode.workspace.fs API #7908 has to be landed
  • prompt to open a binary file
  • prompt to open a large file
  • stream content for Monaco editor to avoid blocking the backend and network communications
  • limit incremental file update to several megabytes, it will crash the backend for large files, for such files we have to go with streaming

Out of scope:

  • electron: bind disk fs provider directly in the renderer process

How to test

  • try to open binary file, for instance generate a tar file
  • try to open/save large file: Improve memory usage for large files microsoft/vscode#30180
    • generate medium size ts less than 32 mb, it should be possible to open both in browser and electron
    • generate large size ts more than 32 mb, it should prompt in the browser and can file on load, in electron it should load without the prompt

Review checklist

Reminder for reviewers

@akosyakov akosyakov added filesystem issues related to the filesystem performance issues related to performance monaco issues related to monaco labels Jul 8, 2020
@akosyakov akosyakov changed the title Ak/opening large or binary files opening large or binary files Jul 8, 2020
@paul-marechal
Copy link
Member

paul-marechal commented Jul 8, 2020

  • stream content for Monaco editor

Is monaco supporting streaming now or will we just stream and buffer the content before giving it to the editor?

@akosyakov
Copy link
Member Author

akosyakov commented Jul 9, 2020

Is monaco supporting streaming now or will we just stream and buffer the content before giving it to the editor?

Yes, there are internal Monaco APIs which allow it: https://code.visualstudio.com/blogs/2018/03/23/text-buffer-reimplementation

@akosyakov akosyakov force-pushed the akosyakov/integrate-vscode-api-7269 branch from 446e385 to aef2b6e Compare July 9, 2020 12:16
@akosyakov akosyakov force-pushed the ak/opening_large_or_binary_files branch 5 times, most recently from 522f5b9 to d55019f Compare July 10, 2020 11:14
@akosyakov
Copy link
Member Author

It works, but it is slow for Electron compare to VS Code. We need to bind DiskFileSystemProvider directly in the electron renderer process as VS Code does, but it requires refactoring of how we fork processes and establish the ipc communication since it should be possible to webpack such code.

@akosyakov akosyakov marked this pull request as ready for review July 10, 2020 14:39
@akosyakov akosyakov force-pushed the ak/opening_large_or_binary_files branch from 55613a1 to 4041d16 Compare July 10, 2020 14:49
@lmcbout
Copy link
Contributor

lmcbout commented Jul 10, 2020

@akosyakov I try to merge as described in the command line instructions and there are many merge conflicts to solved
git checkout -b ak/opening_large_or_binary_files origin/ak/opening_large_or_binary_files
git merge akosyakov/integrate-vscode-api-7269

@marcdumais-work
Copy link
Contributor

@akosyakov I try to merge as described in the command line instructions and there are many merge conflicts to solved
git checkout -b ak/opening_large_or_binary_files origin/ak/opening_large_or_binary_files
git merge akosyakov/integrate-vscode-api-7269

Can't you just checkout branch ak/opening_large_or_binary_files?
i.e., Assuming the remote is named upstream:

git fetch upstream
git checkout --track upstream/ak/opening_large_or_binary_files

Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

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

I verified the functionality of the pull-request and it works as described 👍

Browser:

  • opening a binary file triggers a prompt
  • opening a file smaller than the preference value does not trigger a prompt
  • opening a file larger than the preference value triggers a prompt
  • modifying the preference value is respected

Electron:

  • opening a binary file triggers a prompt
  • opening a file works like master

@lmcbout
Copy link
Contributor

lmcbout commented Jul 13, 2020

I only used the branch for the large file, unable to merge with "git merge akosyakov/integrate-vscode-api-7269", it triggers many conflict merge.
Testing Browser and Electron on UBUNTU 18.04
Result:
The preference is applied for the file max size
After trying to open a binary file, if I select "Yes" , I can open any small files in preview after
If I select "No", then I cannot open any files in preview anymore, just if I double click to open in a regular editor works.

UnableToOpenAfterNo

@lmcbout
Copy link
Contributor

lmcbout commented Jul 13, 2020

After trying to open a large file, I forgot to put the error I see on the console log
When selecting "No", the following error is logged on the console:

root ERROR Failed to initialize for 'file:///home/lmcbout/script/file2000000': Error: Unable to read file 'file2000000' (Error: Unable to read file 'file2000000' that is too large to open)
    at new FileOperationError (http://localhost:3000/0.bundle.js:3039:28)
    at FileService.push.../../packages/filesystem/lib/browser/file-service.js.FileService.asFileOperationError (http://localhost:3000/0.bundle.js:1417:34)
    at FileService.push.../../packages/filesystem/lib/browser/file-service.js.FileService.rethrowAsFileOperationError (http://localhost:3000/0.bundle.js:1414:20)
    at FileService.<anonymous> (http://localhost:3000/0.bundle.js:1390:30)
    at step (http://localhost:3000/0.bundle.js:522:23)
    at Object.throw (http://localhost:3000/0.bundle.js:503:53)
    at rejected (http://localhost:3000/0.bundle.js:495:65)
Caused by: Error: Unable to read file 'file2000000' that is too large to open
    at new FileOperationError (http://localhost:3000/0.bundle.js:3039:28)
    at FileService.push.../../packages/filesystem/lib/browser/file-service.js.FileService.validateReadFileLimits (http://localhost:3000/0.bundle.js:1477:23)
    at FileService.<anonymous> (http://localhost:3000/0.bundle.js:1461:30)
    at step (http://localhost:3000/0.bundle.js:522:23)
    at Object.next (http://localhost:3000/0.bundle.js:503:53)
    at fulfilled (http://localhost:3000/0.bundle.js:494:58)

Then I can open any small file after that in preview mode as I said earlier

@a1994846931931
Copy link
Contributor

I tried to open a large binary file, and the prompt showed twice (one told me the file is too large, after clicking yes, the other told me that the file is a binary), which seems a little bit annoying to me. Maybe you could come up with a better user experience for situation like this?

@akosyakov
Copy link
Member Author

akosyakov commented Jul 14, 2020

thanks for testing, it seems to be that FileResource is not a god place for checks, will try to move to another place. I'm wrong the root of issue is the editor preview widget which tries to open an editor differently multiple times and does not handle exceptions properly.

@akosyakov akosyakov force-pushed the ak/opening_large_or_binary_files branch from 4041d16 to 54d7a5e Compare July 14, 2020 13:57
@akosyakov
Copy link
Member Author

akosyakov commented Jul 14, 2020

@lmcbout @a1994846931931 Could you try again? I've fixed issues with the editor preview extension. There is still some weirdness but it is out of the scope of this PR: #8168

@lmcbout
Copy link
Contributor

lmcbout commented Jul 14, 2020

After trying to open a binary file, if I select "Yes" | "No" , I can open any small files in preview after 👍 FIX

As @a1994846931931 mentioned, If I try to open a large file and it happens that this file is an executable, there are two popup dialogs, we should only have one popup.

LageExec_2_popup

@akosyakov
Copy link
Member Author

akosyakov commented Jul 15, 2020

As @a1994846931931 mentioned, If I try to open a large file and it happens that this file is an executable, there are two popup dialogs, we should only have one popup.

I agree that UX wise is not really good, but I don't feel that it is right to open a binary file if one agreed to open a large file. Unfortunately I cannot to do checks together to add have only one prompt, since the size check is cheap I need only the stat, but to check for binary content I had to actually open the file and fetch in the worst case more than 100kb. I would prefer to keep it like that for now.

Copy link
Contributor

@lmcbout lmcbout left a comment

Choose a reason for hiding this comment

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

I agree that UX wise is not really good, but I don't feel that it is right to open a binary file if one agreed to open a large file. Unfortunately I cannot to do checks together to add have only one prompt, since the size check is cheap I need only the stat, but to check for binary content I had to actually open the file and fetch in the worst case more than 100kb. I would prefer to keep it like that for now.

UX wise not great, I agree. We should not try to open executable file , so I agree to accept this PR as it is right now.
Thanks @akosyakov for your work

@akosyakov akosyakov force-pushed the akosyakov/integrate-vscode-api-7269 branch from 5cf3072 to f408df3 Compare July 27, 2020 13:07
@akosyakov akosyakov force-pushed the ak/opening_large_or_binary_files branch from 54d7a5e to d159210 Compare July 28, 2020 07:55
@akosyakov akosyakov force-pushed the akosyakov/integrate-vscode-api-7269 branch 3 times, most recently from 87c7840 to a8d9c09 Compare August 3, 2020 08:12
@akosyakov akosyakov force-pushed the ak/opening_large_or_binary_files branch from d159210 to b4d0280 Compare August 3, 2020 08:27
Base automatically changed from akosyakov/integrate-vscode-api-7269 to master August 3, 2020 08:52
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
…large files

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
@akosyakov akosyakov force-pushed the ak/opening_large_or_binary_files branch from b4d0280 to b2097c1 Compare August 3, 2020 08:55
@akosyakov akosyakov merged commit b80ac33 into master Aug 3, 2020
@akosyakov akosyakov deleted the ak/opening_large_or_binary_files branch August 3, 2020 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filesystem issues related to the filesystem monaco issues related to monaco performance issues related to performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent opening files that are too large [editor] Opening a big binary file crashes the whole backend
7 participants