You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bugIssue identified by VS Code Team member as probable bugfreeze-slow-crash-leakVS Code crashing, performance, freeze and memory leak issuesimportantIssue identified as high-priorityverifiedVerification succeeded
I don't have exact steps. It was working fine. I was writing node js scripts to split old family videos into individual clips. I was using the built in terminal. Midway through a script I canceled the process. After I fixed and restarted the script I noticed ffmpeg wasn't running. It was frozen or something so I rebooted my computer. It wouldn't restart so I held the power button until it turned off. On reboot I reopened vscode and I can no longer see javascript files:
The file cannot be displayed in the editor because it is either binary or uses an unsupported text encoding.
I can open javascript files from old projects but all the *.js files in the folder I had open in vscode are blank and give the "file cannot be displayed..." message.
garfieldbanks I'm sorry you lost your data. That's bad. However, I'm not yet ready to accept the blame... All your files where saved when you rebooted your box? Did you have autosave enabled or not?
No I don't have autosave on, but I don't think autosave is relevant as this happened to many of the files in the project, most of which were not being edited anywhere near the time of the freeze. There is only one file that I edited before restarting the script and that is the main script itself. But I saved it before restarting the script. So none of my files should have been in an unsaved state.
I'm sorry that I was a little angry when I made this issue. I've since rewritten the code (it wasn't really all that much). I understand that these things happen and I still like vscode.
If there's anything else I can do to help figure out the bug, please let me know.
I don't have auto-save enabled either and lost my pre-existing file when the power cut and I had unsaved changes. Windows 10 Pro, current VSCode release (1.3). The only setting I have altered is using \n as line endings.
I can easily reproduce this with VS Code. But does it reproduce with another applications...?
An interesting experience would be to open VS Code in a workspace (which watches over the files within), use Notepad to edit a file inside that workspace and crash after the save operation. The theory is that the file watching would have some factor in this. After a few attemps, I could reproduce it, but in this case instead of the file being completely zero filled, only the newly added content would be zero filled (I typed 7 bytes before the crash):
Hmmm... I didn't really believe file watching had anything to do with it so I tried reproducing it with Nodepad only. After many attempts, I did it:
While Notepad still has the issue, it does seem to behave a bit better, by limiting the damage to the newly added bytes. So this lead me to compare what Notepad does versus what Code does.
Notepad
Code
Well, both processes seem to write the full file to disk, but Notepad seems to cause two more events (SetEndOfFileInformationFile and SetAllocationInformationFile) to make sure the file is truncated at 1144 bytes... is that really making a difference here? The seem to come from calling SetEndOfFile from KERNELBASE.dll:
Here's the process events. It seems that at least the SetEndOfFileInformationFile event is fired. Not sure how to get the SetAllocationInformationFile.
But that wasn't enough, it seems, as the whole file was zeros, after reproducing the issue:
I decided to stop here, since I don't think we'll get close to Notepad's behaviour. Also, even if we did the issue would only be improved, not fixed.
It's possible that the solution would lie on the SetAllocationInformationFile event, which I have no idea how to call from Node. Another theory is that the CreateFile call is slightly different as well, between Notepad and Node. I couldn't figure out a way to make the same call in Node as its done in Notepad.
I will close this issue as there's not much we can do here.
Mitigation suggestions
use an SCM tool, such as git;
use a backup system, such as Windows Backup and Restore.
Closing arguments
Above all else, note that a crash is an unexpected error which can hardly be always properly handled. Anything can fail (and often will) during a crash, from user-land apps, through the kernel down to actual transistors.
There are a few ideas of how we can mitigate this such as saving the file to another location and only then overwrite the original file; this way there would be copies of the edited files somewhere in disk. But even that can fail: the FS could batch the backup and save operations together and the machine could crash while applying those operations, thus losing all state...
It stands to reason that finding and fixing the source of the crash is the only sane fix; in this case this means charging your battery more often or simply not crash the machine on purpose.
I share all of emragins' concerns, and the additional concern that a bug in Sublime is somehow justification to write this file-destroying issue off, seems far more like "they have to fix it too".
I don't think João Moreno (@joaomoreno) is writing it off. I believe his last comment meant that he was going to be enlisting Benjamin Pasero (@bpasero) to help him figure it out and that he expects to have it done sometime in August.
Ben (@benlowry) The fact that other applications have the same problem means the issue isn't with the applications, but with the OS, file system, kernel, hardware, or something down below.
But the fact that Sublime doesn't seem to have it, by using the FlushBuffers operation, means we can at least be as good as them. This doesn't mean the problem won't exist, we're just going to narrow down the time window in which is it possible to occur. A crash is always a crash, and very little can be done about a crash at the right time.
changed the title [-]The file cannot be displayed in the editor because it is either binary or uses an unsupported text encoding[/-][+]Save: Flush to disk after writing to file[/+]on Aug 8, 2016
bugIssue identified by VS Code Team member as probable bugfreeze-slow-crash-leakVS Code crashing, performance, freeze and memory leak issuesimportantIssue identified as high-priorityverifiedVerification succeeded
Activity
garfieldbanks commentedon Jul 21, 2016
Opened file with notepad and it is blank.
Looks like vscode deleted the contents of my file.
I was really starting to like vscode. But this sucks.
garfieldbanks commentedon Jul 21, 2016
I can open javascript files from old projects but all the *.js files in the folder I had open in vscode are blank and give the "file cannot be displayed..." message.
kieferrm commentedon Jul 22, 2016
garfieldbanks I'm sorry you lost your data. That's bad. However, I'm not yet ready to accept the blame... All your files where saved when you rebooted your box? Did you have autosave enabled or not?
kieferrm commentedon Jul 22, 2016
See also my comment in #9552. The issue describes a similar experience also on W10.
garfieldbanks commentedon Jul 22, 2016
No I don't have autosave on, but I don't think autosave is relevant as this happened to many of the files in the project, most of which were not being edited anywhere near the time of the freeze. There is only one file that I edited before restarting the script and that is the main script itself. But I saved it before restarting the script. So none of my files should have been in an unsaved state.
I'm sorry that I was a little angry when I made this issue. I've since rewritten the code (it wasn't really all that much). I understand that these things happen and I still like vscode.
If there's anything else I can do to help figure out the bug, please let me know.
benlowry commentedon Jul 22, 2016
I don't have auto-save enabled either and lost my pre-existing file when the power cut and I had unsaved changes. Windows 10 Pro, current VSCode release (1.3). The only setting I have altered is using \n as line endings.
joaomoreno commentedon Jul 27, 2016
cc emragins
joaomoreno commentedon Jul 27, 2016
I can easily reproduce this with VS Code. But does it reproduce with another applications...?
An interesting experience would be to open VS Code in a workspace (which watches over the files within), use Notepad to edit a file inside that workspace and crash after the save operation. The theory is that the file watching would have some factor in this. After a few attemps, I could reproduce it, but in this case instead of the file being completely zero filled, only the newly added content would be zero filled (I typed 7 bytes before the crash):
Hmmm... I didn't really believe file watching had anything to do with it so I tried reproducing it with Nodepad only. After many attempts, I did it:
While Notepad still has the issue, it does seem to behave a bit better, by limiting the damage to the newly added bytes. So this lead me to compare what Notepad does versus what Code does.
Notepad
Code
Well, both processes seem to write the full file to disk, but Notepad seems to cause two more events (
SetEndOfFileInformationFileandSetAllocationInformationFile) to make sure the file is truncated at 1144 bytes... is that really making a difference here? The seem to come from callingSetEndOfFilefromKERNELBASE.dll:To be continued...
joaomoreno commentedon Jul 27, 2016
Let's boil it down to a snippet:
It wasn't hard to reproduce the issue with this code: after a few attempts, the whole file was filled with zeros.
So.. let's try to replicate Notepad's behaviour and truncate the file before closing it:
Here's the process events. It seems that at least the
SetEndOfFileInformationFileevent is fired. Not sure how to get theSetAllocationInformationFile.But that wasn't enough, it seems, as the whole file was zeros, after reproducing the issue:
I decided to stop here, since I don't think we'll get close to Notepad's behaviour. Also, even if we did the issue would only be improved, not fixed.
It's possible that the solution would lie on the
SetAllocationInformationFileevent, which I have no idea how to call from Node. Another theory is that theCreateFilecall is slightly different as well, between Notepad and Node. I couldn't figure out a way to make the same call in Node as its done in Notepad.Interesting link: http://stackoverflow.com/questions/12228042/what-does-setfilevaliddata-doing-what-is-the-difference-with-setendoffile
joaomoreno commentedon Jul 27, 2016
I will close this issue as there's not much we can do here.
Mitigation suggestions
Closing arguments
Above all else, note that a crash is an unexpected error which can hardly be always properly handled. Anything can fail (and often will) during a crash, from user-land apps, through the kernel down to actual transistors.
There are a few ideas of how we can mitigate this such as saving the file to another location and only then overwrite the original file; this way there would be copies of the edited files somewhere in disk. But even that can fail: the FS could batch the backup and save operations together and the machine could crash while applying those operations, thus losing all state...
It stands to reason that finding and fixing the source of the crash is the only sane fix; in this case this means charging your battery more often or simply not crash the machine on purpose.
14 remaining items
emragins commentedon Jul 27, 2016
Awesome. Thanks! :)
benlowry commentedon Jul 28, 2016
I share all of emragins' concerns, and the additional concern that a bug in Sublime is somehow justification to write this file-destroying issue off, seems far more like "they have to fix it too".
garfieldbanks commentedon Jul 28, 2016
I don't think João Moreno (@joaomoreno) is writing it off. I believe his last comment meant that he was going to be enlisting Benjamin Pasero (@bpasero) to help him figure it out and that he expects to have it done sometime in August.
joaomoreno commentedon Jul 28, 2016
Ben (@benlowry) The fact that other applications have the same problem means the issue isn't with the applications, but with the OS, file system, kernel, hardware, or something down below.
But the fact that Sublime doesn't seem to have it, by using the
FlushBuffersoperation, means we can at least be as good as them. This doesn't mean the problem won't exist, we're just going to narrow down the time window in which is it possible to occur. A crash is always a crash, and very little can be done about a crash at the right time.[-]The file cannot be displayed in the editor because it is either binary or uses an unsupported text encoding[/-][+]Save: Flush to disk after writing to file[/+]bpasero commentedon Aug 9, 2016
João Moreno (@joaomoreno) I pushed this and would appreciate a verification on Windows with your setup.
joaomoreno commentedon Sep 2, 2016
This seems to work beautifully.
bpasero commentedon Sep 2, 2016
João Moreno (@joaomoreno) thanks for verifying <3
Save: Flush to disk after writing to file (fixes microsoft#9589)