<div dir="ltr"><div>Thanks Michael,<br><br></div>Unfortunately SocketFrameHandler#close invokes &quot;flush&quot; method which then blocks again:<br><br>Thread [Thread-0] (Suspended)    <br>    waiting for: BufferedOutputStream  (id=26)    <br>
        owned by: Thread [main] (Suspended)    <br>    BufferedOutputStream.flush() line: 140    <br>    DataOutputStream.flush() line: 123    <br>    SocketFrameHandler.flush() line: 142    <br>    SocketFrameHandler.close() line: 147    <br>
    Send$2.run() line: 131    <br>    Thread.run() line: 724    <br><br><div><div><div class="gmail_extra">I looked at the implementation of the write timeout in ActiveMQ, here it is:<br><a href="http://opensourcejavaphp.net/java/activemq/org/apache/activemq/transport/WriteTimeoutFilter.java.html" target="_top" rel="nofollow" link="external">http://opensourcejavaphp.net/java/activemq/org/apache/activemq/transport/WriteTimeoutFilter.java.html</a><br>
<br></div><div class="gmail_extra">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<br><pre id="Classes">
<font id="Long">long</font> delta = (filter.getWriter().isWriting() &amp;&amp; writeStart&gt;<font id="IntegerLiteral">0</font>)?System.currentTimeMillis() - writeStart:-<font id="IntegerLiteral">1</font>;</pre>if delta is greater than write timeout they do socket.close().<br>
</div><div class="gmail_extra"><br></div><div class="gmail_extra">If &quot;_socket&quot; field is not private in SocketFrameHandler I could try overriding &quot;close&quot; 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).<br>
</div><div class="gmail_extra">By the way do you know why SocketFrameHandler#close method invokes &quot;flush&quot; first before making socket.close()? Is it ok in case of write timeout just do socket.close() without flush?<br>
</div><div class="gmail_extra"><br></div><div class="gmail_extra">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.<br>
<br></div><div class="gmail_extra">Both workarounds require careful testing and time, we will think about it. But I&#39;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?<br>
<br>Thanks,<br>Oleg<br><br><div class="gmail_quote">2013/10/8 Michael Klishin [via RabbitMQ] <span dir="ltr">&lt;<a href="/user/SendEmail.jtp?type=node&node=30338&i=0" target="_top" rel="nofollow" link="external">[hidden email]</a>&gt;</span><br>
<blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="im">

        <br>On oct 8, 2013, at 2:11 p.m., Oleg Lyalikov &lt;<a href="http://user/SendEmail.jtp?type=node&amp;node=30323&amp;i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>&gt; wrote:
<br><br>&gt; For me the client should have possibility to set such timeout or at least have some workaround - I don&#39;t see any now.
<br><br></div><div class="im">Oleg,
<br><br>I understand your frustration. I will file a bug about this.
<br><br>It should be possible to getFrameHandler on a connection and close its underlying
<br>socket with SocketFrameHandler#close. It does not write any data and catches
<br>any exceptions that may arise. It also does not use the output stream which is
<br>what SocketFrameHandler#writeFrame synchronizes on.
<br><br>So try detecting that the peer is gone in your own code (note: this is *the* fundamental
<br>issue here, not that JDK sockets don&#39;t have a timeout API) and close the socket.
<br>I cannot tell if that may cause the write method to throw but it&#39;s worth trying.
<br><br>Another relatively unintrusive option I can think of is modifying
<br>SocketFramehandler to use a lock that supports timeouts. This way it would be
<br>easier to detect the issue and instantiate a new connection.
<br><br></div><div class="im">MK
<br><br><br><br><br>_______________________________________________
<br>rabbitmq-discuss mailing list
<br><a href="http://user/SendEmail.jtp?type=node&amp;node=30323&amp;i=1" rel="nofollow" link="external" target="_blank">[hidden email]</a>
<br><a href="https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss" rel="nofollow" link="external" target="_blank">https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss</a><br><div><br><img> <b>signature.asc</b> (506 bytes) <a href="http://rabbitmq.1065348.n5.nabble.com/attachment/30323/0/signature.asc" rel="nofollow" link="external" target="_blank">Download Attachment</a></div>


        
        
        
        <br>
        <br>
        <hr color="#cccccc" noshade size="1">
        </div><div style="color:rgb(68,68,68);font:12px tahoma,geneva,helvetica,arial,sans-serif"><div class="im">
                <div style="font-weight:bold">If you reply to this email, your message will be added to the discussion below:</div>
                </div><a href="http://rabbitmq.1065348.n5.nabble.com/Long-timeout-if-server-host-becomes-unreachable-tp30275p30323.html" target="_blank" rel="nofollow" link="external">http://rabbitmq.1065348.n5.nabble.com/Long-timeout-if-server-host-becomes-unreachable-tp30275p30323.html</a>
        </div><div class=""><div class="h5">
        <div style="color:rgb(102,102,102);font:11px/1.5em tahoma,geneva,helvetica,arial,sans-serif;margin-top:0.4em">
                
                To unsubscribe from Long timeout if server host becomes unreachable, <a href="" target="_blank" rel="nofollow" link="external">click here</a>.<br>

                <a href="http://rabbitmq.1065348.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&amp;id=instant_html%21nabble%3Aemail.naml&amp;base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&amp;breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml" rel="nofollow" style="font:9px serif" target="_blank" link="external">NAML</a>
        </div></div></div></blockquote></div><br></div></div></div></div>


        
        
        
<br/><hr align="left" width="300" />
View this message in context: <a href="http://rabbitmq.1065348.n5.nabble.com/Long-timeout-if-server-host-becomes-unreachable-tp30275p30338.html">Re: Long timeout if server host becomes unreachable</a><br/>
Sent from the <a href="http://rabbitmq.1065348.n5.nabble.com/">RabbitMQ mailing list archive</a> at Nabble.com.<br/>