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

AccessDeniedException when using WritingMode.REPLACE_ATOMIC #183

Closed
shartte opened this issue Aug 7, 2024 · 5 comments · Fixed by #184
Closed

AccessDeniedException when using WritingMode.REPLACE_ATOMIC #183

shartte opened this issue Aug 7, 2024 · 5 comments · Fixed by #184
Assignees
Labels
minecraft_forge ⛏️ Reported by or related to MCForge or a Forge mod workaround Not our fault, but we could work around the issue.

Comments

@shartte
Copy link

shartte commented Aug 7, 2024

On Windows, we sometimes run into AccessDeniedExceptions when saving a config rapidly likely due to WindowsDefender locking the config file, preventing it from being replaced.

new TomlWriter().write(config, file, WritingMode.REPLACE_ATOMIC);
com.electronwill.nightconfig.core.io.WritingException: Failed to write (REPLACE_ATOMIC) the config to: C:\AE2\Forge\run\config\ae2-client.toml
	at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.8.0/com.electronwill.nightconfig.core.io.ConfigWriter.write(ConfigWriter.java:105) ~[core-3.8.0.jar%23136!/:?] {}
	at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.8.0/com.electronwill.nightconfig.core.io.ConfigWriter.write(ConfigWriter.java:76) ~[core-3.8.0.jar%23136!/:?] {}
[...]
Caused by: java.nio.file.AccessDeniedException: C:\AE2\Forge\run\config\ae2-client.toml.new.tmp -> C:\AE2\Forge\run\config\ae2-client.toml
	at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89) ~[?:?] {}
	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103) ~[?:?] {}
	at java.base/sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:328) ~[?:?] {}
	at java.base/sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:291) ~[?:?] {}
	at java.base/java.nio.file.Files.move(Files.java:1430) ~[?:?] {}
	at MC-BOOTSTRAP/com.electronwill.nightconfig.core@3.8.0/com.electronwill.nightconfig.core.io.ConfigWriter.write(ConfigWriter.java:92) ~[core-3.8.0.jar%23136!/:?] {}
	... 44 more

In our other tooling we've opted to implement a short retry-loop specifically on Windows and on AccessDeniedExceptions to work around this.

@TheElectronWill
Copy link
Owner

Would it be possible add the config files to the Windows Defender whitelist? A TOML file is just text after all, it's not an executable that should be scanned (the ".tmp" extension may have triggered Defender somehow?)

@shartte
Copy link
Author

shartte commented Aug 8, 2024

Would it be possible add the config files to the Windows Defender whitelist? A TOML file is just text after all, it's not an executable that should be scanned (the ".tmp" extension may have triggered Defender somehow?)

This is not something I can control for players 😓

What I am doing to work around it is to just try to avoid writing the config file in rapid succession, but you know how it goes. If this can crash, it will for some poor chap.

@TheElectronWill
Copy link
Owner

Okay, since multiple people seem to be affected, I'll try to add a workaround. I'll need someone to test it though, as I do not use Windows :)

@Donastria
Copy link

I would be happy to test if you need. I have WAY too many mods that require ForgeConfig that aren't working atm...

@TheElectronWill TheElectronWill self-assigned this Aug 20, 2024
@TheElectronWill TheElectronWill added workaround Not our fault, but we could work around the issue. minecraft_forge ⛏️ Reported by or related to MCForge or a Forge mod and removed minecraft_forge ⛏️ Reported by or related to MCForge or a Forge mod labels Aug 20, 2024
@TheElectronWill
Copy link
Owner

I've opened #184 with a potential fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minecraft_forge ⛏️ Reported by or related to MCForge or a Forge mod workaround Not our fault, but we could work around the issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants