# java.io.IOException: 无法建立与节点 -1 (localhost/127.0.0.1:9092) 的连接。代理可能不可用。

- **ID:** `kafka/socket-server-max-too-low`
- **领域:** kafka
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

代理的套接字服务器最大连接数限制已耗尽，因为来自客户端的并发连接数超过了配置的 socket.server.max.connections 值。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Kafka 3.4.0 | active | — | — |
| Kafka 3.5.0 | active | — | — |
| Kafka 3.6.0 | active | — | — |
| Kafka 3.7.0 | active | — | — |

## 解决方案

1. ```
   Increase the socket.server.max.connections configuration in server.properties and restart the broker:

socket.server.max.connections=2000

Then monitor connections using: netstat -an | grep :9092 | wc -l
   ```
2. ```
   Reduce the number of concurrent connections from clients by implementing connection pooling or batching requests. For example, in a Java consumer, use a single shared KafkaConsumer instance instead of creating per-thread consumers.
   ```

## 无效尝试

- **Restart the broker** — Restarting only temporarily resets connections; the underlying limit is unchanged and will be hit again quickly under high load. (90% 失败率)
- **Increase heap memory for the broker** — Socket server connections are not directly related to heap memory; the issue is a connection count limit, not memory pressure. (95% 失败率)
