[
https://issues.apache.org/jira/browse/SOLR-7419?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14502383#comment-14502383
]
Steve Rowe edited comment on SOLR-7419 at 4/20/15 5:48 AM:
-----------------------------------------------------------
I don't think it's a problem - the {{timeoutAt}} value is never directly
compared - instead the result of subtracting {{nanoTime()}} from it is compared
to zero:
{code:java}
public static Long get() {
return timeoutAt.get();
}
[...]
public boolean shouldExit() {
return get() - nanoTime() < 0L;
}
{code}
This little java program tests some of the overflow cases, and passes for me
with assertions enabled (Java 8):
{code:java}
public class LongOverflowTest {
public static void main(String[] args) {
long start = 1L;
long future = start + Long.MAX_VALUE;
long end = start + 1;
assert future - end > 0L;
end = Long.MAX_VALUE;
assert future - end > 0L;
++end;
assert future - end == 0L;
++end;
assert future - end < 0L;
start = Long.MAX_VALUE;
future = start + Long.MAX_VALUE;
end = start + 1;
assert future - end > 0L;
end = (start - 1) + Long.MAX_VALUE;
assert future - end > 0L;
++end;
assert future - end == 0L;
++end;
assert future - end < 0L;
}
}
{code}
was (Author: steve_rowe):
I don't think it's a problem - the {{timeoutAt}} value is never directly
compared - instead the result of subtracting {{nanoTime()}} from it is compared
to zero:
{code:java}
public static Long get() {
return timeoutAt.get();
}
[...]
public boolean shouldExit() {
return get() - nanoTime() < 0L;
}
{code}
This little java program tests some of the overflow cases, and passes for me
with assertions enabled (Java 8):
{code:java}
public class LongOverflowTest {
public static void main(String[] args) {
long start = 1L;
long future = start + Long.MAX_VALUE;
long end = start + 1;
assert future - end > 0L;
end = Long.MAX_VALUE;
assert future - end > 0L;
++end;
assert future - end == 0L;
start = Long.MAX_VALUE;
future = start + Long.MAX_VALUE;
end = start + 1;
assert future - end > 0L;
end = (start - 1) + Long.MAX_VALUE;
assert future - end > 0L;
++end;
assert future - end == 0L;
++end;
assert future - end < 0L;
}
}
{code}
> Initial value of thread local in SolrQueryTimeoutImpl overflows a long
> ----------------------------------------------------------------------
>
> Key: SOLR-7419
> URL: https://issues.apache.org/jira/browse/SOLR-7419
> Project: Solr
> Issue Type: Bug
> Components: search
> Affects Versions: 4.10.4, 5.1
> Reporter: Shalin Shekhar Mangar
> Priority: Trivial
> Fix For: Trunk, 5.2
>
>
> Same as the title.
> {code}
> /**
> * The ThreadLocal variable to store the time beyond which, the processing
> should exit.
> */
> public static ThreadLocal<Long> timeoutAt = new ThreadLocal<Long>() {
> @Override
> protected Long initialValue() {
> return nanoTime() + Long.MAX_VALUE;
> }
> };
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]