<div dir="ltr">Given the pattern of it, I might be able to produce a PMD checks for this. This way, you could run it across the code base and check for all occurences of it. </div><div class="gmail_extra"><br><div class="gmail_quote">On 10 September 2014 13:58, Alan Field <span dir="ltr">&lt;<a href="mailto:afield@redhat.com" target="_blank">afield@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey Bela,<br>
<span class=""><br>
&gt; Just a quick heads up. I&#39;m currently working on<br>
&gt; <a href="https://issues.jboss.org/browse/JGRP-1877" target="_blank">https://issues.jboss.org/browse/JGRP-1877</a>, which it critical as it may:<br>
&gt; - cause RPCs to return prematurely (possibly with a TimeoutException), or<br>
&gt; - cause RPCs to blocks for a long time (pick which one is worse :-))<br>
<br>
</span>How frequently can these errors occur? Is this something that is not very likely to happen or something that requires an external action to trigger it? (i.e. changing the time via NTP) Just trying to determine the priority of this issue.<br>
<br>
Thanks,<br>
Alan<br>
<div class="HOEnZb"><div class="h5"><br>
----- Original Message -----<br>
&gt; From: &quot;Bela Ban&quot; &lt;<a href="mailto:bban@redhat.com">bban@redhat.com</a>&gt;<br>
&gt; To: <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt; Sent: Wednesday, September 10, 2014 12:05:11 PM<br>
&gt; Subject: [infinispan-dev] JGRP-1877<br>
&gt;<br>
&gt; Just a quick heads up. I&#39;m currently working on<br>
&gt; <a href="https://issues.jboss.org/browse/JGRP-1877" target="_blank">https://issues.jboss.org/browse/JGRP-1877</a>, which it critical as it may:<br>
&gt; - cause RPCs to return prematurely (possibly with a TimeoutException), or<br>
&gt; - cause RPCs to blocks for a long time (pick which one is worse :-))<br>
&gt;<br>
&gt; This is due to my misunderstanding of the semantics of<br>
&gt; System.nanoTime(), I frequently have code like this, which computes a<br>
&gt; future deadline for a timeout:<br>
&gt;<br>
&gt;              long wait_time=TimeUnit.NANOSECONDS.convert(timeout,<br>
&gt; TimeUnit.MILLISECONDS);<br>
&gt;              final long target_time=System.nanoTime() + wait_time;<br>
&gt;              while(wait_time &gt; 0 &amp;&amp; !hasResult) { /* Wait for responses: */<br>
&gt;                  wait_time=target_time - System.nanoTime();<br>
&gt;                  if(wait_time &gt; 0) {<br>
&gt;                      try {cond.await(wait_time, TimeUnit.NANOSECONDS);}<br>
&gt; catch(Exception e) {}<br>
&gt;                  }<br>
&gt;              }<br>
&gt;              if(!hasResult &amp;&amp; wait_time &lt;= 0)<br>
&gt;                  throw new TimeoutException();<br>
&gt;<br>
&gt; Variable target_time can possibly become *negative* if nanoTime()<br>
&gt; returns a negative value. If so, hasResult is false and wait_time<br>
&gt; negative, and therefore a TimeoutException would be thrown !<br>
&gt;<br>
&gt; While I&#39;m at it, I&#39;ll also fix my uses of System.currentTimeMillis(),<br>
&gt; and replace it with nanoTime(). Our good friend Erik has run into issues<br>
&gt; with RPCs (using currentTimeMillis()) hanging forever when their<br>
&gt; NTP-based servers adjusted the time .... backwards !<br>
&gt;<br>
&gt; Please be aware of nanoTime() in your own code, e.g.<br>
&gt; long t0=nanoTime();<br>
&gt; ...<br>
&gt; long t1=nanoTime();<br>
&gt;<br>
&gt; It is *not* guaranteed that t1 &gt; t0 because of numeric overflow (t0<br>
&gt; might be Long.MAX_VALUE-1 and t1 Long.MAX_VALUE +2 !). The only way to<br>
&gt; compare them is t1 - t0 &gt; 0 (t1 is more recent) or &lt; 0 t0 is more recent.<br>
&gt;<br>
&gt; Just thought I wanted to pass this on, in case somebody made the same<br>
&gt; stupid mistake...<br>
&gt;<br>
&gt; Thanks to David Lloyd for pointing this out !<br>
&gt;<br>
&gt; --<br>
&gt; Bela Ban, JGroups lead (<a href="http://www.jgroups.org" target="_blank">http://www.jgroups.org</a>)<br>
&gt; _______________________________________________<br>
&gt; infinispan-dev mailing list<br>
&gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
&gt;<br>
_______________________________________________<br>
infinispan-dev mailing list<br>
<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Romain PELISSE,<br><i>&quot;The trouble with having an open mind, of course, is that people will insist on coming along and trying to put things in it&quot; -- Terry Pratchett</i><br><a href="http://blog.wordpress.belaran.eu/" target="_blank">Belaran ins Prussia (blog)</a>     (... finally up and running !)
</div>