# WebSocket close code 1001: Endpoint Unavailable

- **ID:** `api/websocket-close-code-1001-endpoint-unavailable`
- **Domain:** api
- **Category:** network_error
- **Error Code:** `1001`
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

The server is shutting down or the WebSocket endpoint is temporarily unavailable, causing an intentional close with code 1001.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| WebSocket Protocol RFC 6455 | active | — | — |
| Node.js ws library 8.x | active | — | — |
| Python websockets 11.x | active | — | — |
| Spring WebSocket 6.0+ | active | — | — |

## Workarounds

1. **Implement exponential backoff reconnection logic. Example in JavaScript:
let delay = 1000;
function reconnect() {
  setTimeout(() => {
    const ws = new WebSocket('wss://api.example.com/socket');
    ws.onclose = (event) => {
      if (event.code === 1001) {
        delay = Math.min(delay * 2, 30000);
        reconnect();
      }
    };
  }, delay);
}** (80% success)
   ```
   Implement exponential backoff reconnection logic. Example in JavaScript:
let delay = 1000;
function reconnect() {
  setTimeout(() => {
    const ws = new WebSocket('wss://api.example.com/socket');
    ws.onclose = (event) => {
      if (event.code === 1001) {
        delay = Math.min(delay * 2, 30000);
        reconnect();
      }
    };
  }, delay);
}
   ```
2. **Check server health endpoint before reconnecting to ensure the WebSocket server is back online.** (85% success)
   ```
   Check server health endpoint before reconnecting to ensure the WebSocket server is back online.
   ```
3. **If using a load balancer, verify that health checks are configured correctly for the WebSocket service to avoid routing to unhealthy instances.** (75% success)
   ```
   If using a load balancer, verify that health checks are configured correctly for the WebSocket service to avoid routing to unhealthy instances.
   ```

## Dead Ends

- **** — The server may still be unavailable; immediate reconnection often fails repeatedly and increases server load. (80% fail)
- **** — Code 1001 is a server-initiated close due to unavailability, not a protocol version mismatch. (90% fail)
- **** — Compression settings are unrelated to server endpoint availability. (95% fail)
