> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/reference/error-codes/mariadb-error-codes-1100-to-1199/e1158.md).

# Error 1158: Got an error reading communication packets

Error 1158 diagnostic reference: communication packet read errors, client abort causes, log\_warnings≥4 diagnostics, error log parsing, and perror output.

| Error Code | SQLSTATE | Error                | Description                                |
| ---------- | -------- | -------------------- | ------------------------------------------ |
| 1158       | 08S01    | ER\_NET\_READ\_ERROR | Got an error reading communication packets |

## Possible Causes and Solutions

The server returns this error when reading from a client connection fails: the connection was closed or reset while the server was waiting for the client's next packet. The client usually never sees the error, because the connection is already gone. You find it in the [error log](/docs/server/server-management/server-monitoring-logs/error-log.md) instead, as the reason of an `Aborted connection` warning. The server writes that warning with the default [log\_warnings](/docs/server/server-management/variables-and-modes/server-system-variables.md#log_warnings) of `2` or higher, and counts the connection in the [Aborted\_clients](/docs/server/server-management/variables-and-modes/server-status-variables.md#aborted_clients) status variable:

```
2026-10-23 13:37:58 31 [Warning] Aborted connection 31 to db: 'shop' user: 'app' host: 'localhost' (Got an error reading communication packets)
```

The most common causes are:

* The client program ended, or was killed, without closing its connections, for example an application that exits without calling `mysql_close()` or the close method of its connector.
* Something between the client and the server closed the connection: a firewall, load balancer, or NAT gateway that drops idle connections, or a network failure.
* A connection pool kept connections open that were then cut off, and the server notices when it next reads from them.

To solve the error:

* Make the application close its connections before it exits, and make the connection pool validate connections before it reuses them.
* If a network device drops idle connections, let the pool close idle connections before the device's own idle timeout, or enable TCP keepalive on the client. On the server side, [wait\_timeout](/docs/server/server-management/variables-and-modes/server-system-variables.md#wait_timeout) closes idle connections cleanly.
* Check whether the warnings come from one host or user. That points to the application or network path involved.

Related errors:

* If the server stops waiting because a timeout runs out, such as [wait\_timeout](/docs/server/server-management/variables-and-modes/server-system-variables.md#wait_timeout) or [net\_read\_timeout](/docs/server/server-management/variables-and-modes/server-system-variables.md#net_read_timeout), the reason is [error 1159](/docs/server/reference/error-codes/mariadb-error-codes-1100-to-1199/e1159.md), `Got timeout reading communication packets`, not this error.
* If the client sends a packet larger than [max\_allowed\_packet](/docs/server/server-management/variables-and-modes/server-system-variables.md#max_allowed_packet), the reason is [error 1153](/docs/server/reference/error-codes/mariadb-error-codes-1100-to-1199/e1153.md), and the client gets the client error `2006 (HY000): Server has gone away`.
* If writing to the client fails, the reason is [error 1160](/docs/server/reference/error-codes/mariadb-error-codes-1100-to-1199/e1160.md).

### How to Find Out More

Setting [log\_warnings](/docs/server/server-management/variables-and-modes/server-system-variables.md#log_warnings) to `4` or higher also writes a low-level warning for each failed read:

```
2024-04-19 17:02:11 20090 [Warning] mariadbd: Could not read packet: fd: 4575  state: 1  read_length: 4  errno: 104  vio_errno: 1158  length: -1
```

How to interpret the above:

* `20090` is the connection id that got the warning/error.
* `fd: 4575` 4575 is the file descriptor that had a problem.
* `state: 1` shows that the file is open. Anything else means the file is not active. Note that in some cases MariaDB will try to abort a read on a file descriptor by closing it.
* `read_length: 4` is how many characters the server tried to read from the file.
* `errno 104` is the system error code (more below).
* `vio_errno: 1158` is our internal error code from the vio library, which stands for ER\_NET\_READ\_ERROR "Got an error reading communication packets".
* `length: -1` is how many characters was reported to be read from the read() system call. -1 indicates failure. If `length` <= `read_length` then something broke in the communication.

You can use the perror utility to get a description of system and storage engine errors:

```
shell> perror 104
OS error code 104: Connection reset by peer
```

This means the connection was reset by the other side, the client or a network device between the client and the server.

## See Also

* [perror](/docs/server/clients-and-utilities/administrative-tools/perror.md) Getting a description for an error number.

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}
