Close codes
When the server ends a connection it uses a WebSocket close code between 4000 and 4015. The table is generated from the protocol definition. The last column says whether you may reconnect.
| Code | Name | Meaning | May reconnect |
|---|---|---|---|
| 4000 | UNKNOWN_ERROR | Unknown error | Yes |
| 4001 | UNKNOWN_OPCODE | Unknown opcode | Yes |
| 4002 | DECODE_ERROR | Could not decode | Yes |
| 4003 | NOT_AUTHENTICATED | Not authenticated | Yes |
| 4004 | AUTHENTICATION_FAILED | Authentication failed | No |
| 4005 | ALREADY_AUTHENTICATED | Already authenticated | Yes |
| 4007 | INVALID_SEQUENCE | Invalid sequence for resume | Yes, identify afresh |
| 4008 | RATE_LIMITED | Rate limited | Yes, after waiting |
| 4009 | SESSION_TIMED_OUT | Session timed out | Yes |
| 4010 | TOO_MANY_CONNECTIONS | Too many connections for this token | No, until one closes |
| 4011 | CLIENT_TOO_SLOW | Client too slow | Yes |
| 4012 | TOKEN_REVOKED | Token revoked | No |
| 4013 | INVALID_VERSION | Invalid gateway version | No |
| 4014 | TOO_MANY_FROM_NETWORK | Too many from this network | Yes, once one closes |
| 4015 | UNAVAILABLE | Gateway unavailable, at capacity or switched off | Yes, after waiting |
"Yes" means you can reconnect and resume. Where the table adds a condition, follow it:
- Identify afresh means send IDENTIFY with your token. Do not send RESUME.
- After waiting means pause before reconnecting, and back off if you are closed again.
- Until one closes (4010) and once one closes (4014) mean the limit is on open connections. Close one of yours first. A connection that dropped without closing cleanly keeps counting for up to 90 seconds, until the server times it out with 4009, so a listener that gets 4010 should wait at least 90 seconds before it reconnects. See limits.
If you are told not to reconnect, fix the cause first. Reconnecting with the same token or the same address will get the same close code. Troubleshooting lists the usual fix for each one.
Each close code
4000 UNKNOWN_ERROR
Unknown error. May reconnect: yes.
4001 UNKNOWN_OPCODE
Unknown opcode. May reconnect: yes.
4002 DECODE_ERROR
Could not decode. May reconnect: yes.
4003 NOT_AUTHENTICATED
Not authenticated. May reconnect: yes.
4004 AUTHENTICATION_FAILED
Authentication failed. May reconnect: no.
4005 ALREADY_AUTHENTICATED
Already authenticated. May reconnect: yes.
4007 INVALID_SEQUENCE
Invalid sequence for resume. May reconnect: yes, identify afresh.
4008 RATE_LIMITED
Rate limited. May reconnect: yes, after waiting.
4009 SESSION_TIMED_OUT
Session timed out. May reconnect: yes.
4010 TOO_MANY_CONNECTIONS
Too many connections for this token. May reconnect: no, until one closes.
4011 CLIENT_TOO_SLOW
Client too slow. May reconnect: yes.
4012 TOKEN_REVOKED
Token revoked. May reconnect: no.
4013 INVALID_VERSION
Invalid gateway version. May reconnect: no.
4014 TOO_MANY_FROM_NETWORK
Too many from this network. May reconnect: yes, once one closes.
4015 UNAVAILABLE
Gateway unavailable, at capacity or switched off. May reconnect: yes, after waiting.