Javamail 在超时时不会完全关闭套接字
当通过 javamail 发送邮件时,会打开一个到 smtp 服务器的套接字。现在,我们得到的情况是,当连接仍处于活动状态并且 javamail 正在等待服务器时(垃圾邮件扫描需要几秒钟),邮件服务器的连接断开了。因此 TCP 连接从未真正关闭,客户端陷入死锁。
所以我们决定使用 javamails 超时,它可以工作 - 客户端在指定的时间后抛出异常。但是,tcp 连接未正确关闭(netstat -np 仍将连接显示为“ESTABLISHED”)。仅在我调用 System.gc() 后,套接字才会关闭。
这是一个问题,因为 gc() 在抛出任何 OOM-Exception 之前得到保证,但不是在达到 FD 限制之前......
这可以以某种方式规避吗?或者这是 javamail 中的错误?
受影响的系统:Linux (debian lenny)、Sun JDK 1.6.0.20 (with -XXUseSSE=3)、javamail 1.4.3
When sending a mail trough javamail, a socket to the smtp server is opened. Now, we got the case, that the connection of the mail server went down while the connection was still alive and while javamail was waiting for the server (spam scanning took a few seconds). Therefor the TCP connection was never really closed and the client deadlocked.
So we decided to use javamails timeouts, which works - the client throws an exception after the time specified. However, the tcp connection is NOT correctly closed (netstat -np still shows the connection as "ESTABLISHED"). Only after I call System.gc(), the socket gets closed.
This is a problem, because gc() is guaranteed before any OOM-Exception is thrown, but not before the FD-limit is reached...
Can this be circumvented somehow or is this a bug in javamail?
Affected System: Linux (debian lenny), Sun JDK 1.6.0.20 (with -XXUseSSE=3), javamail 1.4.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该异常不会导致连接关闭,您必须调用 Transport.close()
你自己。
The exception doesn't cause the connection to be closed, you have to call Transport.close()
yourself.