java - Caused by: java.net.NoRouteToHostException: Cannot assign requested address (Address not available)
问题描述
I have java application that connect to mysql on docker. when i run load test to save and update data to mysql, first it run corectly but, after a while i got the
Caused by: java.net.NoRouteToHostException: Cannot assign requested address (Address not available)
and program exit immediately.
my program connect to mysql by hibernate and i used the following code to interact with database:
Session curentSession = sessionFactory.getCurrentSession();
curentTransaction = curentSession.beginTransaction();
curentSession.update(entity);
curentTransaction.commit();
解决方案
似乎当使用getcurrentSession()休眠打开会话时,在事务提交后将其关闭,但 tcp 连接仍以“TIME_WAIT”状态打开,所以当我运行时,netstat -natp
我得到了大量到 3306(mysql 端口)的连接。所以我有两个解决方案:
- 更改我与数据库的连接设计,该设计不会在每个事务中关闭并重新打开连接。
- 更改状态“time_wait”中的连接等待时间:
回声 30 > /proc/sys/net/ipv4/tcp_fin_timeout
此外,我发现在我的情况下更改tcp_fin_timeout并不是一个好的解决方案。我将DriverManagerDataSource更改为dataSource
HikariDataSource并使用maximumPoolSize来管理与 mysql 数据库的连接。所以与mysql数据库的巨大连接问题消失了。;)
祝你好运
推荐阅读
- node.js - 如何加密准系统节点 TCP 套接字之间的流量?
- python - 如何在命令提示符中将 \r\n 显示为实际的换行符?
- laravel - 添加新组时如何打开链接?拉拉维尔
- angular - 表单数组所有控件条件需要验证
- asp.net-mvc - 如何在asp.net中使列表项可点击
- python - 将 Plotly-Dash 与 Tkinter GUI 相结合 - Dash 强制再次执行 Tk-mainloop
- web - 什么是最简单的 Windows 邮件服务器,仅用于发送邮件。邮件服务器?
- flutter - 在 MobX 依赖项的空安全版本上运行 build_runner 时出错
- r - “替换有 2 行,数据有 114591”,带有 foreach 和 doparallel
- javascript - 从移动设备上的 LinkedIn 中的链接查看时,为什么我的 h1 文本跟随垂直页面滚动?