https://bz.apache.org/bugzilla/show_bug.cgi?id=64311

            Bug ID: 64311
           Summary: org.apache.tomcat.jni.TestSocketServerAnyLocalAddress
                    locks entire testbed run under certain conditions
           Product: Tomcat 10
           Version: 10.0.0-M3
          Hardware: All
                OS: FreeBSD
            Status: NEW
          Severity: major
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: micha...@apache.org
  Target Milestone: ------

This took me a bit to find. Following happens with:

* Tomcat master/4d5048f9826627ad9f80627bf28ff7b15bd489ac
* Tomcat native from master
* APR from 1.7.x w/o threading support, testing a patch for Bug 63671
* OpenSSL 1.1.1e-freebsd
* OpenJDK 64-Bit Server VM (build 25.242-b07, mixed mode)
* FreeBSD 12.1-STABLE #0 r359195, amd64
* Network settings:
> bge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
>         
> options=c019b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4,VLAN_HWTSO,LINKSTATE>
>         ether 20:67:7c:d4:58:40
>         inet 147.54.64.17 netmask 0xfffffc00 broadcast 147.54.67.255
>         inet 147.54.64.149 netmask 0xffffffff broadcast 147.54.64.149
>         media: Ethernet autoselect (1000baseT <full-duplex>)
>         status: active
>         nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
> lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
>         options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
>         inet6 ::1 prefixlen 128
>         inet6 fe80::1%lo0 prefixlen 64 scopeid 0x5
>         inet 127.0.0.1 netmask 0xff000000
>         groups: lo
>         nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
* build.properties contains:
> execute.test.apr=true
> java.net.preferIPv4Stack=true

When the test is started, it completely locks up. No progress. What happens:
* APR binds on any socket, in this case it is:
> $ procstat -f 33340
> 33340 java                21 s - rw------   2       0 TCP 0 0 ::.22303 ::.0
* I have applied the following patch to tackle it down:
> diff --git a/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java 
> b/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java
> index 866ba772c5..3e56ebeff3 100644
> --- a/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java
> +++ b/test/org/apache/tomcat/jni/TestSocketServerAnyLocalAddress.java
> @@ -127,0 +128 @@ public class TestSocketServerAnyLocalAddress extends 
> AbstractJniTest {
> +                System.out.println("Connecting to: " + connectAddress);
> @@ -164,0 +166 @@ public class TestSocketServerAnyLocalAddress extends 
> AbstractJniTest {
> +            System.out.println("Listenting at: " + localAddress);
> @@ -188,0 +191 @@ public class TestSocketServerAnyLocalAddress extends 
> AbstractJniTest {
> +                            System.out.println("from enumeration");
> @@ -197,0 +201 @@ public class TestSocketServerAnyLocalAddress extends 
> AbstractJniTest {
> +                            System.out.println("from loopback");
> @@ -200,0 +205 @@ public class TestSocketServerAnyLocalAddress extends 
> AbstractJniTest {
> +                            System.out.println("from linklocal");
> @@ -203,0 +209 @@ public class TestSocketServerAnyLocalAddress extends 
> AbstractJniTest {
> +                            System.out.println("from localhost");

I see then:
> test-nio2:
>     [junit] Running org.apache.tomcat.jni.TestSocketServerAnyLocalAddress in 
> thread 1
>     [junit] Listenting at: /0:0:0:0:0:0:0:0:22303
>     [junit] java.net.ConnectException: Connection refused (Connection refused)
>     [junit] from localhost
>     [junit]     at java.net.PlainSocketImpl.socketConnect(Native Method)
>     [junit] Connecting to: localhost/127.0.0.1:22303
>     [junit]     at 
> java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
>     [junit]     at 
> java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
>     [junit]     at 
> java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
>     [junit]     at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
>     [junit]     at java.net.Socket.connect(Socket.java:607)
>     [junit]     at 
> org.apache.tomcat.jni.TestSocketServerAnyLocalAddress$Client.run(TestSocketServerAnyLocalAddress.java:129)

As soon as I disable the IPv4 preference the connection works on IPv6. Or this
one works with the 10-second timeout:
> $ nc -6 :: 64054

Suprisingly, as soon as I recompile the same APR version with threading support
the behavior of APR changes:
> test-nio2:
>     [junit] Running org.apache.tomcat.jni.TestSocketServerAnyLocalAddress in 
> thread 1
>     [junit] Listenting at: /0.0.0.0:20726
>     [junit] from enumeration
>     [junit] Connecting to: /147.54.64.149:20726
>     [junit] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 
> 0,03 sec, Thread: 1, Class: 
> org.apache.tomcat.jni.TestSocketServerAnyLocalAddress

So I see two bugs here:
* Tomcat test code does not properly handle APR on IPv6, but Java preference on
IPv4
* APR should not change its behavior when threading is disabled or a bug in
libtcnative?

Another compilation of APR: --disable-ipv6 --disable-threads make this run
again.

Positive findings: 
* Almost all tests work w/ OpenSSL 1.1.1 and APR 1.7.x with threads disabled
and IPv6 disabled, java.net.preferIPv4Stack=false, except those:
> org.apache.catalina.session.TestStandardSessionIntegration:
> org.apache.catalina.tribes.group.TestGroupChannelMemberArrival:
> org.apache.catalina.tribes.group.TestGroupChannelStartStop:
> org.apache.catalina.tribes.group.interceptors.TestOrderInterceptor:
> org.apache.catalina.tribes.group.interceptors.TestTcpFailureDetector:
>     org.apache.catalina.tribes.ChannelException: java.net.SocketException: 
> Invalid argument; No faulty members identified.
>         Caused by: java.net.SocketException: Invalid argument
>         at java.net.PlainDatagramSocketImpl.join(Native Method)
>         at 
> java.net.AbstractPlainDatagramSocketImpl.join(AbstractPlainDatagramSocketImpl.java:178)
But this is due to: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=193246
* With java.net.preferIPv4Stack=true all tests pass!

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to