Skip to content

Fix issue with jersey and unix domain sockets#697

Merged
marcuslinke merged 1 commit intomasterfrom
fix-jersey-unixsocket
Sep 10, 2016
Merged

Fix issue with jersey and unix domain sockets#697
marcuslinke merged 1 commit intomasterfrom
fix-jersey-unixsocket

Conversation

@marcuslinke
Copy link
Contributor

@marcuslinke marcuslinke commented Sep 7, 2016

This eliminates the socket already closed exception (org.newsclub.net.unix.AFUNIXSocketException: Bad file descriptor). The problem occurs when the underlying connection of a stream is closed and chunked encoding is active. The apache ChunkedInputStream still tries to read till the end of the current chunk while close()ing itself. This is not possible as the connection/socket is already closed.

Sadly it needs to fix two classes AFUNIXSocketImpl and ChunkedInputStream to solve the issue.

This change is Reviewable

pom.xml Outdated
<artifactId>junixsocket-native-common</artifactId>
<version>${junixsocket.version}</version>
</dependency>
<dependency>
Copy link
Contributor Author

@marcuslinke marcuslinke Sep 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependency to jnr-unixsocket must be removed...

@marcuslinke marcuslinke force-pushed the fix-jersey-unixsocket branch from d410911 to 066f177 Compare September 8, 2016 20:30
pom.xml Outdated
<!-- </extension> -->
<!-- </extensions> -->
<!-- <extensions> -->
<!-- <extension> -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

@KostyaSha
Copy link
Member

👍

@marcuslinke
Copy link
Contributor Author

@KostyaSha What is the difference between the two travis builds continuous-integration/travis-ci/pushand continuous-integration/travis-ci/pr ?

@KostyaSha
Copy link
Member

Obviously pull request and branch build ;)

@KostyaSha
Copy link
Member

So if you don't plan cooperate on branch, then do branch in your fork and open PR.

@KostyaSha
Copy link
Member

(com.github.dockerjava.core.command.EventsCmdImplTest)  Time elapsed: 29.805 sec  <<< FAILURE!
java.lang.AssertionError: Received only: [] expected [true] but found [false]
    at com.github.dockerjava.core.command.EventsCmdImplTest.testEventStreamingWithFilter(EventsCmdImplTest.java:122)
Results :
Failed tests: 
com.github.dockerjava.core.command.EventsCmdImplTest.(com.github.dockerjava.core.command.EventsCmdImplTest)
  Run 1: PASS
  Run 2: PASS
  Run 3: PASS
  Run 4: EventsCmdImplTest.testEventStreamingWithFilter:122->Assert.assertTrue:42->Assert.failNotEquals:513->Assert.fail:94 Received only: [] expected [true] but found [false]

retriggering build

@codecov-io
Copy link

codecov-io commented Sep 9, 2016

Current coverage is 71.09% (diff: 47.03%)

Merging #697 into master will decrease coverage by 0.20%

@@             master       #697   diff @@
==========================================
  Files           300        302     +2   
  Lines          6202       6484   +282   
  Methods           0          0          
  Messages          0          0          
  Branches        528        585    +57   
==========================================
+ Hits           4422       4610   +188   
- Misses         1531       1594    +63   
- Partials        249        280    +31   

Powered by Codecov. Last update 74d506d...066f177

@KostyaSha
Copy link
Member

Also place somewhere in javadoc why clases was copied.

@marcuslinke marcuslinke force-pushed the fix-jersey-unixsocket branch 2 times, most recently from ea6bdbc to e51b898 Compare September 9, 2016 21:13
@marcuslinke marcuslinke merged commit d39d7f2 into master Sep 10, 2016
@marcuslinke marcuslinke deleted the fix-jersey-unixsocket branch September 10, 2016 16:54
tejksat pushed a commit to tejksat/docker-java that referenced this pull request Sep 13, 2016
@KostyaSha KostyaSha added this to the 3.0.6 milestone Sep 13, 2016
@KostyaSha
Copy link
Member

@marcuslinke please set milestones before merge and update changelog after merge

@KostyaSha
Copy link
Member

[WARNING] docker-java-3.0.6.jar, httpcore-4.4.5.jar define 1 overlapping classes: 
[WARNING]   - org.apache.http.impl.io.ChunkedInputStream
[WARNING] docker-java-3.0.6.jar, junixsocket-common-2.0.4.jar define 5 overlapping classes: 
[WARNING]   - org.newsclub.net.unix.AFUNIXSocketImpl$AFUNIXOutputStream
[WARNING]   - org.newsclub.net.unix.AFUNIXSocketImpl
[WARNING]   - org.newsclub.net.unix.AFUNIXSocketImpl$AFUNIXInputStream
[WARNING]   - org.newsclub.net.unix.AFUNIXSocketImpl$Lenient
[WARNING]   - org.newsclub.net.unix.AFUNIXSocketImpl$1

@KostyaSha
Copy link
Member

KostyaSha commented Sep 13, 2016

@marcuslinke where ChunkedInputStream is used? or do you trying replace classes? Classes are messed..

@KostyaSha
Copy link
Member

On mac after shading i have

Caused by: java.lang.UnsatisfiedLinkError: com.github.kostyasha.yad_docker_java.org.newsclub.net.unix.NativeUnixSocket.connect(Ljava/lang/String;Ljava/io/FileDescriptor;)V
    at com.github.kostyasha.yad_docker_java.org.newsclub.net.unix.NativeUnixSocket.connect(Native Method)
    at com.github.kostyasha.yad_docker_java.org.newsclub.net.unix.AFUNIXSocketImpl.connect(AFUNIXSocketImpl.java:137)
    at com.github.kostyasha.yad_docker_java.org.newsclub.net.unix.AFUNIXSocket.connect(AFUNIXSocket.java:107)
    at com.github.kostyasha.yad_docker_java.com.github.dockerjava.jaxrs.ApacheUnixSocket.connect(ApacheUnixSocket.java:62)
    at com.github.kostyasha.yad_docker_java.com.github.dockerjava.jaxrs.UnixConnectionSocketFactory.connectSocket(UnixConnectionSocketFactory.java:74)
    at com.github.kostyasha.yad_docker_java.org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
    at com.github.kostyasha.yad_docker_java.org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
    at com.github.kostyasha.yad_docker_java.org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
    at com.github.kostyasha.yad_docker_java.org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
    at com.github.kostyasha.yad_docker_java.org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    at com.github.kostyasha.yad_docker_java.org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
    at com.github.kostyasha.yad_docker_java.org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at com.github.kostyasha.yad_docker_java.org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at com.github.kostyasha.yad_docker_java.org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:71)
    at com.github.kostyasha.yad_docker_java.org.glassfish.jersey.apache.connector.ApacheConnector.apply(ApacheConnector.java:435)
    at com.github.kostyasha.yad_docker_java.org.glassfish.jersey.client.ClientRuntime.invoke(ClientRuntime.java:252)
    ... 81 more

Will try compare with linux env and plain docker-java.

@KostyaSha
Copy link
Member

M... it impossible relocate java class because it depends on native library?

@marcuslinke
Copy link
Contributor Author

@KostyaSha Yes, I've replaced two classes as described in the first comment. Didn't know that this is a problem with shading... :(

@KostyaSha
Copy link
Member

Well, it warning, but having conflicting package-class is questionable.

@marcuslinke
Copy link
Contributor Author

Yes, thats ugly but fixing this in upstream projects (apache HTTPCore AND junixsockets) would take ages I think.

@papegaaij
Copy link

You cannot simply copy a class an expect it to shadow a class from a dependency. This all depends on classloading order, which can be non-deterministic in some cases (such as packaging multiple jars in a war or ear). Your only options are to get this fixed upstream or to work around this some other way. The currently solution breaks our build because the maven-enforcer-plugin detects duplicate classes.

panuse pushed a commit to TuKangTech/docker-java that referenced this pull request Aug 20, 2017
@alexburchak
Copy link

alexburchak commented Oct 3, 2017

My project became a victim of the class loading order issue :)
ChunkedInputStream in docker-java (from the commit), which has that try/catch fix, is not loaded and original class implementation from httpcore is used instead.
Exception thrown in close() method (after invoking read()) is not caught and thus propagated above.
Even worse, the code is catching one of ConnectionClosedException or TruncatedChunkException, but instead of the last one, there should have been MalformedChunkCodingException (it's parent).

dbyron0 pushed a commit to locationlabs/docker-java that referenced this pull request Jan 2, 2019
and because we no longer need our custom version of AFUNIXSocketImpl from docker-java#697
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants