Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixed
- Made HTTP transport stop cleanup idempotent during Unity domain reloads, avoiding disposed `HttpListener` errors when reload cleanup runs after the listener has already been closed.
- Recognize Windows `HttpListenerException` address-in-use error codes and messages during restart retry detection.

## [0.3.4] - 2026-05-20

### Added
Expand Down
15 changes: 13 additions & 2 deletions Editor/MCP/Server/HttpMCPTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,27 @@ public Task StopAsync()

public void Stop()
{
if (!_isRunning) return;
if (!_isRunning && _listener == null) return;
try
{
_cts?.Cancel();
_listener?.Stop();
_listener?.Close();
_isRunning = false;
PluginDebugLogger.Log("[Funplay MCP Server] HTTP transport stopped");
}
catch (ObjectDisposedException)
{
PluginDebugLogger.Log("[Funplay MCP Server] HTTP transport was already disposed");
}
catch (Exception ex)
{
Debug.LogError($"[Funplay MCP Server] Error stopping HTTP transport: {ex.Message}");
}
finally
{
_isRunning = false;
_listener = null;
}
}

private void CleanupFailedStart()
Expand All @@ -130,6 +138,9 @@ private static bool IsAddressInUse(Exception ex)
return ex is HttpListenerException listenerException &&
(listenerException.ErrorCode == 48 ||
listenerException.ErrorCode == 98 ||
listenerException.ErrorCode == 183 ||
listenerException.ErrorCode == 10048 ||
listenerException.Message.IndexOf("Only one usage", StringComparison.OrdinalIgnoreCase) >= 0 ||
listenerException.Message.IndexOf("Address already in use", StringComparison.OrdinalIgnoreCase) >= 0);
}

Expand Down