[rabbitmq-discuss] Long timeout if server host becomes unreachable
oleg.lyalikov at gmail.com
Tue Oct 8 14:48:08 BST 2013
Unfortunately SocketFrameHandler#close invokes "flush" method which then
Thread [Thread-0] (Suspended)
waiting for: BufferedOutputStream (id=26)
owned by: Thread [main] (Suspended)
BufferedOutputStream.flush() line: 140
DataOutputStream.flush() line: 123
SocketFrameHandler.flush() line: 142
SocketFrameHandler.close() line: 147
Send$2.run() line: 131
Thread.run() line: 724
I looked at the implementation of the write timeout in ActiveMQ, here it is:
The solution they use looks workable - it seems they register socket write
start time + keep boolean whether writing occurs right now and then check
in the separate thread
long delta = (filter.getWriter().isWriting() &&
writeStart>0)?System.currentTimeMillis() - writeStart:-1;
if delta is greater than write timeout they do socket.close().
If "_socket" field is not private in SocketFrameHandler I could try
overriding "close" method and invoke just _socket.close() - maybe that
would help. But the field is private (maybe we can copy/paste the class and
instantiate our new one but it does not look good - it would be better to
just enhance existing functionality not to replace - there could be some
problems with compatibility with newer versions of RabbitMQ client lib,
RabbitMQ tests should be run regularly as our own tests, etc).
By the way do you know why SocketFrameHandler#close method invokes "flush"
first before making socket.close()? Is it ok in case of write timeout just
do socket.close() without flush?
As for modifying SocketFrameHandler so that it will use locks with timeouts
- that could be possible but with the same drawbacks as the solution above.
Both workarounds require careful testing and time, we will think about it.
But I'm hoping RabbitMQ library will provide functionality to set socket
write timeout in the future. Could you provide some ticket link so that we
can monitor its status?
2013/10/8 Michael Klishin [via RabbitMQ] <
ml-node+s1065348n30323h50 at n5.nabble.com>
> On oct 8, 2013, at 2:11 p.m., Oleg Lyalikov <[hidden email]<http://user/SendEmail.jtp?type=node&node=30323&i=0>>
> > For me the client should have possibility to set such timeout or at
> least have some workaround - I don't see any now.
> I understand your frustration. I will file a bug about this.
> It should be possible to getFrameHandler on a connection and close its
> socket with SocketFrameHandler#close. It does not write any data and
> any exceptions that may arise. It also does not use the output stream
> which is
> what SocketFrameHandler#writeFrame synchronizes on.
> So try detecting that the peer is gone in your own code (note: this is
> *the* fundamental
> issue here, not that JDK sockets don't have a timeout API) and close the
> I cannot tell if that may cause the write method to throw but it's worth
> Another relatively unintrusive option I can think of is modifying
> SocketFramehandler to use a lock that supports timeouts. This way it would
> easier to detect the issue and instantiate a new connection.
> rabbitmq-discuss mailing list
> [hidden email] <http://user/SendEmail.jtp?type=node&node=30323&i=1>
> *signature.asc* (506 bytes) Download Attachment<http://rabbitmq.1065348.n5.nabble.com/attachment/30323/0/signature.asc>
> If you reply to this email, your message will be added to the discussion
> To unsubscribe from Long timeout if server host becomes unreachable, click
View this message in context: http://rabbitmq.1065348.n5.nabble.com/Long-timeout-if-server-host-becomes-unreachable-tp30275p30338.html
Sent from the RabbitMQ mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rabbitmq-discuss