# Unhandled exception: IsolateSpawnException: Failed to send message: SendPort is already closed

- **ID:** `flutter/isolate-send-port-closed`
- **Domain:** flutter
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

An attempt was made to send a message via a SendPort that has been closed, typically because the receiving isolate has terminated or the port was disposed.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Flutter 3.13.0 | active | — | — |
| Dart 3.1.0 | active | — | — |

## Workarounds

1. **Check if the receiving isolate is still alive before sending. Use a shared flag or a ping mechanism: if (receivePort.isClosed) { await spawnIsolate(); } then send.** (85% success)
   ```
   Check if the receiving isolate is still alive before sending. Use a shared flag or a ping mechanism: if (receivePort.isClosed) { await spawnIsolate(); } then send.
   ```
2. **Implement a reconnection strategy: when the error occurs, close the old SendPort, spawn a new isolate, and recreate the port pair. Example: isolate = await Isolate.spawn(entryPoint, receivePort.sendPort); sendPort = isolate.controlPort;** (80% success)
   ```
   Implement a reconnection strategy: when the error occurs, close the old SendPort, spawn a new isolate, and recreate the port pair. Example: isolate = await Isolate.spawn(entryPoint, receivePort.sendPort); sendPort = isolate.controlPort;
   ```
3. **Use a dedicated communication manager that monitors isolate lifecycle and automatically re-establishes ports on termination.** (75% success)
   ```
   Use a dedicated communication manager that monitors isolate lifecycle and automatically re-establishes ports on termination.
   ```

## Dead Ends

- **Increase the size of the isolate's message queue.** — The error is not about queue capacity but about the port being closed; queue size does not affect closed ports. (95% fail)
- **Wrap the send call in a try-catch and ignore the error.** — Ignoring the error leads to silent data loss; the root cause (port closure) remains unaddressed. (80% fail)
