Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException #1

Closed
jekamax opened this issue Feb 26, 2015 · 1 comment · Fixed by #3
Closed

ArrayIndexOutOfBoundsException #1

jekamax opened this issue Feb 26, 2015 · 1 comment · Fixed by #3

Comments

@jekamax
Copy link

jekamax commented Feb 26, 2015

Hello!
I try to send 15Mb buffer from server to client and get some internal error in client side during receiving.
Is it bug or I do something wrong?

Test case is the following:

  1. Server waits for connection.
  2. Client opens connection and waits for data.
  3. Server sends some data.
public class Main
{
    public static void main(String[] args)
    {
        try
        {
            //stub data to send
            final byte[] bulk = new byte[15 * 1024 * 1024];
            Arrays.fill(bulk, (byte) 0xAF);

            final InetSocketAddress local = new InetSocketAddress(InetAddress.getLocalHost(), 12345);

            //The Server.
            Thread server = new Thread()
            {
                @Override
                public void run()
                {
                    try
                    {
                        UtpServerSocketChannel server = UtpServerSocketChannel.open();
                        server.bind(local);
                        UtpAcceptFuture acceptFuture = server.accept();
                        acceptFuture.block();
                        UtpSocketChannel channel = acceptFuture.getChannel();
                        ByteBuffer out = ByteBuffer.allocate(bulk.length);
                        out.put(bulk);
                        //Send data
                        UtpWriteFuture fut = channel.write(out);
                        fut.block();
                        channel.close();
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace(System.err);
                    }
                }
            };
            server.start();

            //The Client.
            UtpSocketChannel channel = UtpSocketChannel.open();
            UtpConnectFuture cFut = channel.connect(local);
            cFut.block();
            ByteBuffer buffer = ByteBuffer.allocate(bulk.length);
            //Receive data. --EVERYTHING BREAKS UP HERE--
            UtpReadFuture readFuture = channel.read(buffer);
            readFuture.block();
            channel.close();
        }
        catch (Exception e)
        {
            e.printStackTrace(System.err);
        }
    }
}

And I get the following out:

DEBUG [18:14:25] UtpSocketChannel - [Syn send] [ConnID Sending: 720] [ConnID Recv: 719] [SeqNr. 1] [AckNr: 0]
DEBUG [18:14:25] UtpSocketChannel - [Syn recieved] [ConnID Sending: 719] [ConnID Recv: 720] [SeqNr. 25329] [AckNr: 1]
DEBUG [18:14:25] UtpSocketChannelImpl - sending syn ack
DEBUG [18:14:25] UtpAlgorithm - MINIMUM_TIMEOUT_MILLIS: 500 PACKET_SIZE_MODE: CONSTANT_1472 MAX_PACKET_SIZE: 1472 MIN_PACKET_SIZE: 150 MINIMUM_MTU: 576 MAX_CWND_INCREASE_PACKETS_PER_RTT: 3000 C_CONTROL_TARGET_MICROS: 100000 SEND_IN_BURST: true MAX_BURST_SEND: 5 MIN_SKIP_PACKET_BEFORE_RESEND: 3 MICROSECOND_WAIT_BETWEEN_BURSTS: 28000 TIME_WAIT_AFTER_FIN_MICROS: 3000000 ONLY_POSITIVE_GAIN: false DEBUG: false
DEBUG [18:14:25] UtpSocketChannelImpl - starting scheduler
DEBUG [18:14:25] UtpSocketChannel - [SynAck recieved] [ConnID Sending: 720] [ConnID Recv: 719] [SeqNr. 2] [AckNr: 0]
ERROR [18:14:25] SkippedPacketBuffer - seq, exp: 25329 1
java.lang.ArrayIndexOutOfBoundsException: 25328
        at net.utp4j.channels.impl.read.SkippedPacketBuffer.bufferPacket(SkippedPacketBuffer.java:66)
        at net.utp4j.channels.impl.read.UtpReadingRunnable.handleUnexpectedPacket(UtpReadingRunnable.java:250)
        at net.utp4j.channels.impl.read.UtpReadingRunnable.run(UtpReadingRunnable.java:107)
java.io.IOException
        at net.utp4j.channels.impl.read.SkippedPacketBuffer.bufferPacket(SkippedPacketBuffer.java:72)
        at net.utp4j.channels.impl.read.UtpReadingRunnable.handleUnexpectedPacket(UtpReadingRunnable.java:250)
        at net.utp4j.channels.impl.read.UtpReadingRunnable.run(UtpReadingRunnable.java:107)
DEBUG [18:14:25] UtpReadingRunnable - Buffer position: 0 buffer limit: 15728640
DEBUG [18:14:25] UtpReadingRunnable - PAYLOAD LENGHT 0
DEBUG [18:14:25] UtpReadingRunnable - READER OUT
DEBUG [18:15:07] UtpWritingRunnable - buffer position: 4356 buffer limit: 15728640
@pafgoncalves
Copy link

I also stumbled on this problem, and it is impossible not catch it.
The net.utp4j.channels.impl.UtpSocketChannelImpl class has a problem on the line 226.
The sequence number is initialized with a random number when it should be initialized with 1.

setupRandomSeqNumber(); should be replaced with setSequenceNumber(DEF_SEQ_START);.

I don't understand the purpose of setupRandomSeqNumber function because the sequence number should never be random!!

Eragoneq added a commit that referenced this issue Mar 7, 2024
@Eragoneq Eragoneq mentioned this issue Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants