[ 
https://issues.apache.org/jira/browse/NET-501?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Julián Lastiri updated NET-501:
-------------------------------

    Description: 
I'm getting the following exception while disconnecting a threaded 
(readerThread=true) TelnetClient connection. 

Exception in thread "Thread-160" java.lang.IllegalStateException: Queue is 
full! Cannot process another character.
        at 
org.apache.commons.net.telnet.TelnetInputStream.__processChar(TelnetInputStream.java:339)
        at 
org.apache.commons.net.telnet.TelnetInputStream.run(TelnetInputStream.java:647)
        at java.lang.Thread.run(Thread.java:722)

I noticed that when TelnetClient.disconnect() is called the attribute 
__threaded is set to false while the thread in the TelnetInputStream.run() 
method could call TelnetInputStream().__processChar(...) throwing 
IllegalStateException


This is a test program to reproduce the issue

public class TestTelnetClient implements Runnable {

        /**
         * @param args
         */
        public static void main(String[] args) {
                ArrayList<Thread> workers = new ArrayList<Thread>();
                for( int i=0; i<1000; ++i){
                        Thread t = new Thread ( new TestTelnetClient() );
                        t.start();
                        workers.add(t);
                }
                for (Thread t : workers ) {                     
                        try {
                                t.join();                       
                        } catch (InterruptedException e) {
                                e.printStackTrace();
                        }
                }                       

        }

        @Override
        public void run() {
                System.out.println("Starting thread...");
                TelnetClient tc = new TelnetClient();
//              tc.setReaderThread(false);
                try {
                        tc.connect("localhost", 23);
                        tc.setSoTimeout(1000);
                        InputStream in = tc.getInputStream();
                        int ch;
                        in.read();
                } catch (SocketException e) {
                        e.printStackTrace();
                } catch (IOException e) {
                        e.printStackTrace();
                } finally {
                        System.out.println("Disconnecting...");
                        try {
                                tc.disconnect();
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                }
                
        }

}

A telnet server (telnetd) is required. I also modified the initial banner ( 
/etc/issue.net ) with a lot of characters to get a better chance to receive 
information while calling disconnect.

  was:
I'm getting the following exception while disconnecting a threaded 
(readerThread=true) TelnetClient connection. 

Exception in thread "Thread-160" java.lang.IllegalStateException: Queue is 
full! Cannot process another character.
        at 
org.apache.commons.net.telnet.TelnetInputStream.__processChar(TelnetInputStream.java:339)
        at 
org.apache.commons.net.telnet.TelnetInputStream.run(TelnetInputStream.java:647)
        at java.lang.Thread.run(Thread.java:722)

I noticed that when TelnetClient.disconnect() is called the attribute 
__threaded is set to false while the thread in the TelnetInputStream.run() 
method could call TelnetInputStream().__processChar(...) throwing 
IllegalStateException

    
> Race Condition on TelnetClient.disconnect() and TelnetInputStream.run() . 
> java.lang.IllegalStateException: Queue is full! Cannot process another 
> character.
> -----------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: NET-501
>                 URL: https://issues.apache.org/jira/browse/NET-501
>             Project: Commons Net
>          Issue Type: Bug
>          Components: Telnet
>    Affects Versions: 3.2
>         Environment: Ubuntu 12.04 64 bits x86
>            Reporter: Julián Lastiri
>
> I'm getting the following exception while disconnecting a threaded 
> (readerThread=true) TelnetClient connection. 
> Exception in thread "Thread-160" java.lang.IllegalStateException: Queue is 
> full! Cannot process another character.
>       at 
> org.apache.commons.net.telnet.TelnetInputStream.__processChar(TelnetInputStream.java:339)
>       at 
> org.apache.commons.net.telnet.TelnetInputStream.run(TelnetInputStream.java:647)
>       at java.lang.Thread.run(Thread.java:722)
> I noticed that when TelnetClient.disconnect() is called the attribute 
> __threaded is set to false while the thread in the TelnetInputStream.run() 
> method could call TelnetInputStream().__processChar(...) throwing 
> IllegalStateException
> This is a test program to reproduce the issue
> public class TestTelnetClient implements Runnable {
>       /**
>        * @param args
>        */
>       public static void main(String[] args) {
>               ArrayList<Thread> workers = new ArrayList<Thread>();
>               for( int i=0; i<1000; ++i){
>                       Thread t = new Thread ( new TestTelnetClient() );
>                       t.start();
>                       workers.add(t);
>               }
>               for (Thread t : workers ) {                     
>                       try {
>                               t.join();                       
>                       } catch (InterruptedException e) {
>                               e.printStackTrace();
>                       }
>               }                       
>       }
>       @Override
>       public void run() {
>               System.out.println("Starting thread...");
>               TelnetClient tc = new TelnetClient();
> //            tc.setReaderThread(false);
>               try {
>                       tc.connect("localhost", 23);
>                       tc.setSoTimeout(1000);
>                       InputStream in = tc.getInputStream();
>                       int ch;
>                       in.read();
>               } catch (SocketException e) {
>                       e.printStackTrace();
>               } catch (IOException e) {
>                       e.printStackTrace();
>               } finally {
>                       System.out.println("Disconnecting...");
>                       try {
>                               tc.disconnect();
>                       } catch (IOException e) {
>                               // TODO Auto-generated catch block
>                               e.printStackTrace();
>                       }
>               }
>               
>       }
> }
> A telnet server (telnetd) is required. I also modified the initial banner ( 
> /etc/issue.net ) with a lot of characters to get a better chance to receive 
> information while calling disconnect.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to