Bug 59286

Summary: Socket binding failures when using APR
Product: Tomcat Native Reporter: Coty Sutherland <csutherl>
Component: LibraryAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 1.2.5   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Attachments: Exception stack trace

Description Coty Sutherland 2016-04-07 18:24:01 UTC
Created attachment 33737 [details]
Exception stack trace

When using APR for a connector and trying to bind to an ipv6 address (other than lo ::1 or all ::), the connector fails to initialize with a "[22] Invalid argument" exception. I'm using the default server.xml with the address attribute added on the Connectors to reproduce. I noticed that the error is coming up from the Socket.bind() call, but I wanted to open this with the AprEndpoint in mind because it isn't crashing in the natives. Also note that I am using OpenJDK 8u77 for my testing.

This only occurs with APR (NIO/NIO2 seem OK). I'm testing with APR 1.5.2 and OpenSSL 1.0.2g:

07-Apr-2016 12:02:28.415 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library 1.2.6 using APR version 1.5.2.
07-Apr-2016 12:02:28.415 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
07-Apr-2016 12:02:28.417 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized (OpenSSL 1.0.2g-fips  1 Mar 2016)

I put a breakpoint on the bind call, but the working (lo) bind and the non-working one look pretty much identical. I am not familiar with network/socket programming, so it's pretty foreign to me.

This does occur on tomcat-trunk as well.
Comment 1 Coty Sutherland 2016-04-11 13:49:31 UTC
It looks like this affects httpd as well. That and the fact that the Socket.bind() returns the 22 status is cause enough to start looking into APR instead of Tomcat's AprEndpoint I think.
Comment 2 Coty Sutherland 2016-04-11 19:05:51 UTC
It looks like this fails when using an ipv6 link-local scoped address. If you use a globally scoped address, then it works normally. Is that behavior expected with APR?
Comment 3 Coty Sutherland 2016-04-14 13:47:02 UTC
Sorry for all the movement on this one...Moving to tcnative instead of APR. I've finally isolated the issue down to being a problem with link-local IPv6 and found a bugzilla (https://bz.apache.org/bugzilla/show_bug.cgi?id=52717) that already tried to address the problem a few years ago. I guess that makes this a duplicate and the other should be reopened, but I'll leave that up to you guys.
Comment 4 Mark Thomas 2019-06-20 13:39:16 UTC
I've just tested this with the latest 9.0.x and Tomcat Native 1.2.x and all works as expected although I'll note that I had to use telnet for testing as the browser was doing odd things with the IPv6 address.