解决 Odyssey 报错 Cannot assign requested address 短连接端口耗尽修复
排查 高性能连接池 Odyssey 报 client connect failed: Cannot assign requested address (errno 99),分析 TCP 本地端口耗尽与 TIME_WAIT 积压。
问题现象
极高并发压力下,应用连接 Odyssey 代理时突然爆发连接失败:
2026-11-16 11:15:02 [error] (server/0) connect(): Cannot assign requested address (99)
触发根因
- Odyssey 与后端数据库之间频繁新建并销毁短连接;
- 操作系统的临时端口(Ephemeral Ports)在
TIME_WAIT状态下耗尽,内核无法为新发起的 TCP 套接字分配可用源端口; - Odyssey 配置了 pool session 模式而不是 pool transaction,导致后端物理连接复用率不足。
解决步骤
开启 Linux 内核快速重用 TIME_WAIT 套接字
编辑 /etc/sysctl.conf:
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240 65535
net.ipv4.tcp_fin_timeout = 15
执行使其生效:
sudo sysctl -p
调整 Odyssey 路由模式为事务池模式
在 odyssey.conf 中开启高效复用:
storage "postgres_server" {
type "remote"
host "127.0.0.1"
port 5432
}
database "my_app" {
user default {
authentication "clear_text"
pool "transaction"
pool_size 100
pool_timeout 1000
}
}
验证确认
重启 Odyssey 服务:
在每秒数万并发下,套接字平稳复用,Errno 99 彻底消失。


