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

data loss possible on forced kill #3967

Closed
andreaskremser opened this issue Sep 25, 2022 · 8 comments · Fixed by #9236
Closed

data loss possible on forced kill #3967

andreaskremser opened this issue Sep 25, 2022 · 8 comments · Fixed by #9236
Labels
A-core Area: Helix core improvements C-bug Category: This is a bug

Comments

@andreaskremser
Copy link

andreaskremser commented Sep 25, 2022

Summary

when editing a huge (e.g. >80K lines) C-file, the editor sometimes gets unresponsive for extended time periods (up to several minutes).
Killing the hanging editor has in one instance deleted the bottom half of the file, while only a few lines have actually been edited.

Reproduction Steps

I tried this:

  1. hx huge_c_file.c
    edit a few lines
    -> editor hangs, possibly due to language server
    force-kill hx

I expected this to happen:
In best case staying responsive ;)
Losing the latest changes is OK.

Instead, this happened:
Losing lines (about half the file), which have not been edited within the current editing session.. is unexpected.

Platform

Linux (fedora 36)

Terminal Emulator

konsole

Helix Version

helix 22.08.01

@andreaskremser andreaskremser added the C-bug Category: This is a bug label Sep 25, 2022
@dead10ck
Copy link
Member

I actually suspected this was possible, but I wasn't sure. This confirms it for me. This is happening because every time we save, we truncate the file and write out the document text fresh:

let mut file = File::create(path).await?;
to_writer(&mut file, encoding, &text).await?;

I think the solution here is to write it to a temporary file first and then move over the existing file.

@dead10ck dead10ck added E-easy Call for participation: Experience needed to fix: Easy / not much A-core Area: Helix core improvements labels Sep 25, 2022
@startup-stack-sculptor
Copy link

@dead10ck Nice approach to first write to a different file instead of overwriting document directly.

@dead10ck
Copy link
Member

dead10ck commented Oct 2, 2022

It's the easiest way to avoid the problem. But I actually wonder what other editors do. This would be a really inefficient way to write a very large file.

@ngraham20
Copy link
Contributor

I can poke at this

@ngraham20
Copy link
Contributor

Ok, as far as quick research goes, it seems vim handles this by using swap files that are stored either in the working directory or a specified location. This swap file contains info like undo/redo histories and the state of the file as an autosave. This allows recoveries due to crashes. Maybe helix could do something similar?

https://www.cs.longwood.edu/VimSwap.html#:~:text=The%20reason%20this%20message%20comes,your%20undo%2Fredo%20history).

@the-mikedavis
Copy link
Member

#401 might be the fix for this along those lines

@ngraham20
Copy link
Contributor

Should we still add this temporary workaround, as that looks like a bigger code change?

@timokoesters
Copy link

I just had this problem and it wiped out the entire file. I was using rust formatter and the rust lsp and I think I triggered it by hitting ctrl-z followed by ctrl-c (because it seemed to hang).

A fix or temporary workaround would be great. Fortunately I didn't lose much data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Helix core improvements C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants