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

Corrupted config file #152

Open
oltreseba opened this issue Jul 27, 2021 · 6 comments
Open

Corrupted config file #152

oltreseba opened this issue Jul 27, 2021 · 6 comments

Comments

@oltreseba
Copy link

We have been using conf with an electron* for a while with encryption enabled.

Somehow it's happening to something like 1 out of 100-300 users that the config.json file gets corrupted. We are noticing this happening more to Windows users with also Avast antivirus installed (maybe it's messing with the read/write, or maybe is just a coincidence)

The error we are getting is

SyntaxError: Unxpected Token in JSON at position 0

That is the classical error when JSON.parse fails.

Notes:

  • *We already developed our own ipc system before this was added to electron-store, so no renderer is writing the file, and only one process (main) is writing the file

Did this ever happen to anybody?
Is there a way to prevent it?
Is it possible that if the app is killed/quitted while writing then the file is messed up? (I see that atomically is being used, so this shouldn't the case).

@oltreseba oltreseba changed the title Corrupted file. Corrupted config file Jul 27, 2021
@sindresorhus
Copy link
Owner

the config.json file gets corrupted

Corrupted in what way? Empty file? Invalid JSON?

@sindresorhus
Copy link
Owner

From past experience, issues like these are often connected to anti-virus software.

@oltreseba
Copy link
Author

It's hard to tell how it was corrupted as the file was encrypted and even losing one byte will result in a completely meaningless file.

There is an error in the json decode because the content does not start with a standard json (not with a { i guess) i can't tell more than this at the current time.

In which way antivirus is messing up with our files? is there a way we can go around this?

@oltreseba
Copy link
Author

Would it make sense to backup the file at the end of each write, so either the default file or the backup should be fine? (maybe 1 save behind, but at least not corrupted?)

@sindresorhus
Copy link
Owner

It's hard to say what the correct fix would be without being able to reliably reproduce the issue.

@sindresorhus
Copy link
Owner

You could try to replace this call:

atomically.writeFileSync(this.path, data);

with:

fs.writeFileSync(this.path, data);

To see if the problem is with the atomic writing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants