Skip to content

FileLogStorage: IOException Sharing Violation on domain reload when MCP server is running #500

@hhyeon0306

Description

@hhyeon0306

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

  1. Start Unity Editor with the plugin installed
  2. Start Claude Code with unity-mcp-server.exe running via stdio
  3. Modify any .cs file to trigger domain reload
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions