You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Wei Feng Niu <wn...@bea.com> on 2007/08/17 09:29:57 UTC

returns true thought there is no listener

Hi,

         I have a target to detect whether a port is listening, like the
following:

================================================================

<project name="test" default="test.server">

    <target name="test.server" description="Test server.">

        <echo message="trying to test server at localhost:39001..." />

        <waitfor maxwait="300" maxwaitunit="second" checkevery="5"
timeoutproperty="server.not.started">

            <and>

                <socket server="localhost" port="39001" />

            </and>

        </waitfor>

        <fail message="server did not start!" if="server.not.started" />

        <echo message="server has started successfully." />

    </target>

</project>

=================================================================

Put the codes into a build file and run it, I got the following result:

ant -f t.xml;netstat -an|grep 39001

Buildfile: t.xml

 

test.server:

     [echo] trying to test server at localhost:39001...

     [echo] server has started successfully.

 

BUILD SUCCESSFUL

Total time: 59 seconds

tcp        0      0 ::ffff:127.0.0.1:39001      ::ffff:127.0.0.1:39001
TIME_WAIT   

 

 

Thoug there is no any server on 39001 started, after a while the target
will return with "server has started successfully". It is very strange.
Seems the <socket> task makes a listener on 39001 and detect it. So far
I just found the problem on RedHat Linux. And the time that <socket>
returns are different every time you run the target. Sometimes the
target works as expected and sometimes works as above.

 

Does anybody know what's the cause? Thanks

 

Best regards

Weifeng Niu
Tel: +86 10 8528 1188 ext. 1724 

weifeng.niu@bea.com <ma...@bea.com> 

 


Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

Re: returns true thought there is no listener

Posted by Wayne Cannon <wc...@turinnetworks.com>.
I haven't been monitoring this thread very closely, but if I'm not off 
base, the following points may explain some of what you are seeing.  I'm 
not a TCP expert, but have been burned in the past and had to learn the 
following the hard way.

-- When you "close" a socket, it actually remains in a kind of limbo 
state, usually four minutes (two times the "maximum segment lifetime") 
or more, before it actually goes away.  This is to prevent the 
socket/port from being reused during that time so delayed packets from 
the earlier "incarnation" of the connection aren't received and 
misinterpreted by a new connection on that port.  [Stevens, "TCP/IP 
Illustrated: Volume 1, The Protocols"]

-- Many (most?) well-behaved applications use a predefined port only to 
establish a connection, and set up a temporary port provided by TCP for 
subsequent operations.  "Dynamic and/or Private Ports are those from 
49152 through 65535" [Internet Assigned Number Authority -- 
http://www.iana.org/assignments/port-numbers].  This threshold used to 
be much lower.  Most applications don't seem to abide by these 
"well-known" "registered" port numbers once you get above 1024 -- and 
occasionally have conflicts as a result.

--Wayne
>> Does anybody know what's the cause? Thanks
>
> 1. <socket> tries to open a TCP connection; it gets assigned some 
> random port..I'd be surprised that it got 39001, though it is a high 
> enough value it could happen sometimes. Maybe it depends where the TCP 
> stack starts allocating unallocated ports. Try opening a socket to a 
> remote site, see what gets opened there.
>
> 2. run netstat -p to see the process with the port
>
> 3. are you sure the port is closed? Sometimes after a previous run the 
> port may still be open.
>
> -steve

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


Re: returns true thought there is no listener

Posted by Steve Loughran <st...@apache.org>.
Wei Feng Niu wrote:
> Hi,
> 
>          I have a target to detect whether a port is listening, like the
> following:
> 
> ================================================================
> 
> <project name="test" default="test.server">
> 
>     <target name="test.server" description="Test server.">
> 
>         <echo message="trying to test server at localhost:39001..." />
> 
>         <waitfor maxwait="300" maxwaitunit="second" checkevery="5"
> timeoutproperty="server.not.started">
> 
>             <and>
> 
>                 <socket server="localhost" port="39001" />
> 
>             </and>
> 
>         </waitfor>
> 
>         <fail message="server did not start!" if="server.not.started" />
> 
>         <echo message="server has started successfully." />
> 
>     </target>
> 
> </project>
> 
> =================================================================
> 
> Put the codes into a build file and run it, I got the following result:
> 
> ant -f t.xml;netstat -an|grep 39001
> 
> Buildfile: t.xml
> 
>  
> 
> test.server:
> 
>      [echo] trying to test server at localhost:39001...
> 
>      [echo] server has started successfully.
> 
>  
> 
> BUILD SUCCESSFUL
> 
> Total time: 59 seconds
> 
> tcp        0      0 ::ffff:127.0.0.1:39001      ::ffff:127.0.0.1:39001
> TIME_WAIT   
> 
>  
> 
>  
> 
> Thoug there is no any server on 39001 started, after a while the target
> will return with "server has started successfully". It is very strange.
> Seems the <socket> task makes a listener on 39001 and detect it. So far
> I just found the problem on RedHat Linux. And the time that <socket>
> returns are different every time you run the target. Sometimes the
> target works as expected and sometimes works as above.
> 
>  
> 
> Does anybody know what's the cause? Thanks

1. <socket> tries to open a TCP connection; it gets assigned some random 
port..I'd be surprised that it got 39001, though it is a high enough 
value it could happen sometimes. Maybe it depends where the TCP stack 
starts allocating unallocated ports. Try opening a socket to a remote 
site, see what gets opened there.

2. run netstat -p to see the process with the port

3. are you sure the port is closed? Sometimes after a previous run the 
port may still be open.

-steve

2.

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


Re: returns true thought there is no listener

Posted by Stephan Schröder <si...@gmx.de>.

Wei Feng Niu wrote:
> 
> ...Thoug there is no any server on 39001 started, after a while the target
> will return with "server has started successfully". It is very strange.
> Seems the <socket> task makes a listener on 39001 and detect it...

I have the same problem just with XP and port 80 and 8080. The socket-task
confirms an open port although Tomcat hasn't been startet yet.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<target name="isTomcat-Running">
  <condition property="tomcat.online">
    <socket port="8080" server="localhost"/>
  </condition>
  <echo>online? ${tomcat.online}</echo>
</target>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<

This always returns "online? true" for the ports 80 and 8080 (but not for
random ports like 8089).
"netstat -an" and "Process And Port Analyzer 2.0" confirm that there is no
process listening on these ports. ("netstat -p" just gives an empty list.)
Is this an ant problem or does XP (or Kaspersky Anti-Virus) listen on these
ports without telling anyone?
(I wrote that code on a different computer than i'm using now. On the old
computer (Vista) it worked fine.)

regards,
Stephan
-- 
View this message in context: http://old.nabble.com/%3Csocket%3E-returns-true-thought-there-is-no-listener-tp12195287p26694376.html
Sent from the Ant - Users mailing list archive at Nabble.com.


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


RE: returns true though there is no listener

Posted by Wei Feng Niu <wn...@bea.com>.
If you reduce checkevery="5" to checkevery="1", the issue will come out
more frequently

Best regards
Weifeng Niu
Tel: +86 10 8528 1188 ext. 1724 
weifeng.niu@bea.com


-----Original Message-----
From: Wei Feng Niu [mailto:wniu@bea.com] 
Sent: Friday, August 17, 2007 3:30 PM
To: user@ant.apache.org
Subject: <socket> returns true thought there is no listener

Hi,

         I have a target to detect whether a port is listening, like the
following:

================================================================

<project name="test" default="test.server">

    <target name="test.server" description="Test server.">

        <echo message="trying to test server at localhost:39001..." />

        <waitfor maxwait="300" maxwaitunit="second" checkevery="5"
timeoutproperty="server.not.started">

            <and>

                <socket server="localhost" port="39001" />

            </and>

        </waitfor>

        <fail message="server did not start!" if="server.not.started" />

        <echo message="server has started successfully." />

    </target>

</project>

=================================================================

Put the codes into a build file and run it, I got the following result:

ant -f t.xml;netstat -an|grep 39001

Buildfile: t.xml

 

test.server:

     [echo] trying to test server at localhost:39001...

     [echo] server has started successfully.

 

BUILD SUCCESSFUL

Total time: 59 seconds

tcp        0      0 ::ffff:127.0.0.1:39001      ::ffff:127.0.0.1:39001
TIME_WAIT   

 

 

Though there is no any server on 39001 started, after a while the target
will return with "server has started successfully". It is very strange.
Seems the <socket> task makes a listener on 39001 and detect it. So far
I just found the problem on RedHat Linux. And the time that <socket>
returns are different every time you run the target. Sometimes the
target works as expected and sometimes works as above.

 

Does anybody know what's the cause? Thanks

 

Best regards

Weifeng Niu
Tel: +86 10 8528 1188 ext. 1724 

weifeng.niu@bea.com <ma...@bea.com> 

 


Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

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