-
-
Notifications
You must be signed in to change notification settings - Fork 121
Description
Description
On every domain reload (script compilation, entering/exiting play mode), Unity console outputs IOException: Sharing violation errors for ai-editor-logs.txt and its retry files (ai-editor-logs-2.txt, etc.).
This happens because the MCP server process (unity-mcp-server.exe) already holds the log file open for writing, and FileLogStorage attempts to open the same file with FileShare.Read, which prevents concurrent write access.
Environment
- Unity: 6000.3.8f1 (Unity 6)
- Plugin version: 0.49.1
- OS: Windows 10/11
- MCP client: Claude Code (stdio transport)
Reproduction Steps
- Start Unity Editor with the plugin installed
- Start Claude Code with
unity-mcp-server.exerunning via stdio - Modify any
.csfile to trigger domain reload - Observe Unity console
Error Output
[Exception] IOException: Sharing violation on path C:\...\Temp\mcp-server\ai-editor-logs.txt
FileLogStorage.CreateWriteStream() at FileLogStorage.cs:116
[Error] fail: BufferedFileLogStorage Failed to create log file stream for ai-editor-logs.txt. Retrying with a different file name.
[Exception] IOException: Sharing violation on path C:\...\Temp\mcp-server\ai-editor-logs-2.txt
FileLogStorage.CreateWriteStream() at FileLogStorage.cs:116
[Error] fail: BufferedFileLogStorage Failed to create log file stream for ai-editor-logs-2.txt. Retrying with a different file name.
Root Cause
In FileLogStorage.cs:116:
var stream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.Read, bufferSize: _fileBufferSize, useAsync: false);FileShare.Read only allows other processes to read the file. Since unity-mcp-server.exe already has the file open for writing, the FileStream constructor throws IOException.
Suggested Fix
Change FileShare.Read to FileShare.ReadWrite to allow concurrent write access:
var stream = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite, bufferSize: _fileBufferSize, useAsync: false);This is a one-line change in Runtime/Unity/Logs/FileLogStorage.cs:116.
Impact
- Functional impact: None — the retry mechanism eventually finds an available filename
- User experience: 4 error/exception logs appear in Unity console on every domain reload, which is distracting during development
Workaround
Set Log Level to Exception or None in the AI Game Developer window to suppress these logs.