goatcorp / Dalamud

FFXIV plugin framework and API
GNU Affero General Public License v3.0
1.15k stars 271 forks source link

Sometimes Dev Plugin fail to reload on a Win11 Dev Drive #1328

Closed Haselnussbomber closed 4 months ago

Haselnussbomber commented 1 year ago

I've recently upgraded to the Windows 11 Insider Preview and have set up a Dev Drive that uses ReFS. Every now and then, Dalamud can't reload my Dev Plugin and fails with these errors:

2023-07-29 18:08:35.398 +02:00 [DBG] [PLUGIN] Skipping reload of MyPlugin, file has changed again.
2023-07-29 18:08:35.399 +02:00 [INF] [LOCALPLUGIN] Unloading MyPlugin.dll
2023-07-29 18:08:35.399 +02:00 [DBG] [PLUGIN] Skipping reload of MyPlugin, file has changed again.
2023-07-29 18:08:35.459 +02:00 [INF] [LOCALPLUGIN] Finished unloading MyPlugin.dll
2023-07-29 18:08:35.462 +02:00 [INF] LASTEXCEPTION:<snip>
2023-07-29 18:08:35.460 +02:00 [ERR] [LOCALPLUGIN] Error while loading MyPlugin
System.IO.IOException: The process cannot access the file 'F:\cs\ffxiv\DalamudPlugins\MyPlugin\bin\MyPlugin.json' because it is being used by another process.
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
   at System.IO.File.ReadAllText(String path, Encoding encoding)
   at Dalamud.Plugin.Internal.Types.Manifest.LocalPluginManifest.Load(FileInfo manifestFile) in C:\goatsoft\companysecrets\dalamud\Plugin\Internal\Types\Manifest\LocalPluginManifest.cs:line 86
   at Dalamud.Plugin.Internal.Types.LocalPlugin.ReloadManifest() in C:\goatsoft\companysecrets\dalamud\Plugin\Internal\Types\LocalPlugin.cs:line 659
   at Dalamud.Plugin.Internal.Types.LocalPlugin.LoadAsync(PluginLoadReason reason, Boolean reloading) in C:\goatsoft\companysecrets\dalamud\Plugin\Internal\Types\LocalPlugin.cs:line 526
2023-07-29 18:08:35.463 +02:00 [INF] LASTEXCEPTION:<snip>
2023-07-29 18:08:35.463 +02:00 [ERR] [PLUGIN] DevPlugin reload failed.
System.IO.IOException: The process cannot access the file 'F:\cs\ffxiv\DalamudPlugins\MyPlugin\bin\MyPlugin.json' because it is being used by another process.
   at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
   at System.IO.File.ReadAllText(String path, Encoding encoding)
   at Dalamud.Plugin.Internal.Types.Manifest.LocalPluginManifest.Load(FileInfo manifestFile) in C:\goatsoft\companysecrets\dalamud\Plugin\Internal\Types\Manifest\LocalPluginManifest.cs:line 86
   at Dalamud.Plugin.Internal.Types.LocalPlugin.ReloadManifest() in C:\goatsoft\companysecrets\dalamud\Plugin\Internal\Types\LocalPlugin.cs:line 659
   at Dalamud.Plugin.Internal.Types.LocalPlugin.LoadAsync(PluginLoadReason reason, Boolean reloading) in C:\goatsoft\companysecrets\dalamud\Plugin\Internal\Types\LocalPlugin.cs:line 526
   at Dalamud.Plugin.Internal.Types.LocalPlugin.ReloadAsync() in C:\goatsoft\companysecrets\dalamud\Plugin\Internal\Types\LocalPlugin.cs:line 621
   at Dalamud.Plugin.Internal.Types.LocalDevPlugin.<>c__DisplayClass15_0.<<OnFileChanged>b__0>d.MoveNext() in C:\goatsoft\companysecrets\dalamud\Plugin\Internal\Types\LocalDevPlugin.cs:line 166

As a workaround I simply rebuild the plugin again.

The json file is generated by DalamudPackager v2.1.11.

Maybe the code in https://github.com/goatcorp/Dalamud/blob/master/Dalamud/Plugin/Internal/Types/LocalDevPlugin.cs#L127 should check if all needed files are accessible, and if not, retry a few times. Or, probably better, the packager should send a notification to Dalamud vid IPC after it’s done.

KazWolfe commented 1 year ago

If I remember correctly, this is a bit of a race between the compiler/Packager building things and our own code. I’ve seen similar issues happen on normal systems in response to just bad luck.

We may consider making this more resilient though.

robindegen commented 8 months ago

I've had issues with devdrive in general. I tried building a discord bot and when it was running from the devdrive it would randomly fail to connect with a huge ssl error. When I moved it to a regular drive it was all fine. I've also seen it not being able to load files; similar to this.

I think there are some issues with devdrive in general; which may not be fixable here other than trying again but it will just keep failing likely

goaaats commented 4 months ago

I didn't test this explicitly, but I removed the code that would write to the manifest when reloading. Please reopen this if you're still running into issues.

robindegen commented 4 months ago

It looks like microsoft fixed this on their end. I haven't really had issues like this with devdrive for a while now. When it was just introduced it happened regularly.