You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2004/01/06 23:03:56 UTC

DO NOT REPLY [Bug 25935] New: - telnet task does not explicitly disconnect telnet sessions

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25935>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25935

telnet task does not explicitly disconnect telnet sessions

           Summary: telnet task does not explicitly disconnect telnet
                    sessions
           Product: Ant
           Version: 1.7Alpha (nightly)
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Optional Tasks
        AssignedTo: dev@ant.apache.org
        ReportedBy: carcher@yahoo.com


The TelnetTask class does not close it's connections which leads to exhaustion
of telnet sessions on some Telnet servers, such as the Microsoft Windows 2000
Telnet Server (which is limited to two concurrent sessions).

To reproduce, execute the following build.xml against a Windows 2000 Telnet server:

<?xml version="1.0"?>
<project name="telnet test" default="default">
  <property name="server" value="server"/>
  <property name="prompt" value="C:\&gt;"/>
  <property name="command" value="dir"/>
  <target name="default">
    <telnet server="${server}" 
            userid="userid" 
            password="password" 
            timeout="30">
      <read string="${prompt}"/>
      <write string="${command}"/>
      <read string="${prompt}"/>
    </telnet>
    <sleep seconds="1"/>
  </target>
  <target name="test">
    <antcall target="default"/>
    <antcall target="default"/>
    <antcall target="default"/>
    <antcall target="default"/>
  </target>
</project>

Ant will simply hang on the third invocation of the <telnet> task.  The
still-connected sessions can also be viewed on the telnet server machine using
the Telnet Admin program.

I've created a patch against the latest from CVS which ensures that Telnet
connections are closed:

Index: TelnetTask.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java,v
retrieving revision 1.21
diff -u -r1.21 TelnetTask.java
--- TelnetTask.java	23 Oct 2003 09:06:43 -0000	1.21
+++ TelnetTask.java	6 Jan 2004 21:36:17 -0000
@@ -135,24 +135,37 @@
        }
 
        /**  Create the telnet client object */
-       telnet = new AntTelnetClient();
        try {
-           telnet.connect(server, port);
-       } catch (IOException e) {
-           throw new BuildException("Can't connect to " + server);
-       }
-       /**  Login if userid and password were specified */
-       if (userid != null && password != null) {
-          login();
+           telnet = new AntTelnetClient();
+           try {
+               telnet.connect(server, port);
+           } catch (IOException e) {
+               throw new BuildException("Can't connect to " + server);
+           }
+           /**  Login if userid and password were specified */
+           if (userid != null && password != null) {
+              login();
+           }
+           /**  Process each sub command */
+           Enumeration tasksToRun = telnetTasks.elements();
+           while (tasksToRun != null && tasksToRun.hasMoreElements()) {
+               TelnetSubTask task = (TelnetSubTask) tasksToRun.nextElement();
+               if (task instanceof TelnetRead && defaultTimeout != null) {
+                   ((TelnetRead) task).setDefaultTimeout(defaultTimeout);
+               }
+               task.execute(telnet);
+           }
        }
-       /**  Process each sub command */
-       Enumeration tasksToRun = telnetTasks.elements();
-       while (tasksToRun != null && tasksToRun.hasMoreElements()) {
-           TelnetSubTask task = (TelnetSubTask) tasksToRun.nextElement();
-           if (task instanceof TelnetRead && defaultTimeout != null) {
-               ((TelnetRead) task).setDefaultTimeout(defaultTimeout);
+       finally {
+           /**  Close connection for Telnet servers with connection limits */
+           if (telnet != null) {
+               try {
+                   telnet.disconnect();
+               } catch (IOException e) {
+                   throw new BuildException("Error disconnecting from " + server);
+               }
+               telnet = null;
            }
-           task.execute(telnet);
        }
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org