Common session errors and closures
Common session errors and closures
In WebSocket based connections, closures and errors represent different ways a connection can terminate.
A closure is a normal, expected termination initiated by either the client or the server, whereas errors are terminations resulting from an unexpected problem like network issues, protocol mismatches, timeouts, or server-side issues.
In the event of an error, the on_error
callback is triggered just prior to on_close
. If an error is not encountered, then only on_close
is called.
When a session closes, the on_close
callback receives a status code and reason detailing why the connection ended.
This information is useful when attempting to debug issues or handle certain closure scenarios programmatically.
The below table lists some of the common reasons for a session closure along with their corresponding codes and descriptions.
Handling closed sessions
A common way to handle a closure such as 3005 - Session Expired: Maximum session duration exceeded
is to parse the status code and reason in the on_close
callback. If a specific code and reason are detected, you can then take appropriate action, such as opening a new session or logging useful debugging information.
Note that the on_error
callback is not triggered in this case, as the session closes for a known reason and not due to encountering an error.
If you believe your session received an error or closed due to a reason not listed above, please reach out to support@assemblyai.com with the session id and any further details.