You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Srikanth Veeramachaneni (JIRA)" <ji...@apache.org> on 2007/06/19 16:37:26 UTC
[jira] Commented: (DIRMINA-374) ArrayIndexOutOfBoundException in
SocketAcceptor and SocketConnector
[ https://issues.apache.org/jira/browse/DIRMINA-374?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12506188 ]
Srikanth Veeramachaneni commented on DIRMINA-374:
-------------------------------------------------
This might be very trivial, but I don't believe that the fix works when processorCount is greater than 1. It doesn't ensure proper distribution and actually generates a negative index when processorCount is greater than 2.
- The first problem is that the check for negative is being done after the increment in "if ( processorDistributor++ < 0 )".
- The second problem is that the index restarts from 0 irrespective of the previous index value which doesn't ensure proper distribution (this is very trivial, but we might as well fix it while addressing the first issue).
Here is a patch which I believe will address the issue the correct way.
Index: trunk/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
===================================================================
--- trunk/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java (revision 548724)
+++ trunk/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java (working copy)
@@ -427,12 +427,12 @@
private SocketIoProcessor nextProcessor()
{
- if ( processorDistributor++ < 0 )
- {
- processorDistributor = 0;
- }
+ if ( this.processorDistributor == Integer.MAX_VALUE )
+ {
+ this.processorDistributor = Integer.MAX_VALUE % this.processorCount;
+ }
- return ioProcessors[processorDistributor % processorCount];
+ return ioProcessors[processorDistributor++ % processorCount];
}
private void registerNew()
> ArrayIndexOutOfBoundException in SocketAcceptor and SocketConnector
> -------------------------------------------------------------------
>
> Key: DIRMINA-374
> URL: https://issues.apache.org/jira/browse/DIRMINA-374
> Project: MINA
> Issue Type: Bug
> Components: Core
> Affects Versions: 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.1.0
> Reporter: Trustin Lee
> Priority: Critical
> Fix For: 1.0.4, 1.1.1, 2.0.0-M1
>
>
> From Mladen Turk <mt...@apache.org>:
> Hi,
> Here is the patch that fixes the SocketAcceptor.nextProcessor()
> The problem is that round robin distributor is integer and
> if you set the number of processors to > 1, after MAX_INTEGER
> requests (yes I know I tested that many :) it starts throwing
> something like:
> java.lang.ArrayIndexOutOfBoundsException: -3
> The reason?
> -value % 1 is always 0|1
> -value % 2 is always 0|-1
> Anyhow, enough math, here is the patch.
> Regards,
> Mladen.
> Index: SocketAcceptor.java
> ===================================================================
> --- SocketAcceptor.java (revision 533579)
> +++ SocketAcceptor.java (working copy)
> @@ -422,7 +422,11 @@
> private SocketIoProcessor nextProcessor()
> {
> - return ioProcessors[processorDistributor++ % processorCount];
> + if ( processorDistributor++ < 0 )
> + {
> + processorDistributor = 0;
> + }
> + return ioProcessors[processorDistributor % processorCount];
> }
> private void registerNew()
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.