# server-shutting-down

The server **shuts down**, so the request ended before it was through.

- **Routes:** `write-events`, `read-events`, `observe-events`, `run-eventql-query`, `register-event-schema`, `read-subjects`, `read-event-types`, `create-backup`, `restore-backup`, `import-events`, `verify-store`, and `audit-history`
- **Description:** `database is shutting down: try again later`
- **Details:** None; `details` is an empty object.

## Why It Happens

When the server begins to shut down, it **ends the operations that still run**, such as reads, observations, queries, backups, restores, imports, verifications, and audits, and refuses further writes. A write that ends with this error has written **none of its events**, a restore that ends with it has emptied the database again, and an import that ends with it has removed what it imported and kept the schemas that were registered before it.

It arrives as an error only **once the response has started**: when the stream has sent items, or, on the routes that answer only once they are done, such as writing events, at least one `heartbeat`. **Before that**, the same is answered with status **`503 Service Unavailable`** and the text `database is shutting down: try again later`, as is every request that arrives once the shutdown has begun, see **[Errors](/docs/eventsourcingdb/api#errors)**. Reading a single event type, which answers with a single envelope, always gets the `503`.

## How to Fix It

Send the request again **once the server is running again**; it can succeed then. A read or an observation can go on after the last event it received, with a `lowerBound`; a backup, a verification, or an audit that ended this way has **no result** and has to run anew.

## Example

For a read of the events of `/books/42` during which the server begins to shut down, EventSourcingDB sends this error after the events it has sent so far, as a line of the stream, and then ends the stream with its `end` item:

```json
{
  "type": "error",
  "data": {
    "code": "https://docs.eventsourcingdb.io/errors/server-shutting-down",
    "description": "database is shutting down: try again later",
    "details": {}
  }
}
```
