Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSSE: fix deadlock issues between SSLSocket close() and OutputStream write() #230

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

cconlon
Copy link
Member

@cconlon cconlon commented Nov 6, 2024

This PR fixes a few deadlock issues that could occur between SSLSocket.close() and the associated SSLSocket's OutputStream.write().

Originally from user report of deadlock, was similar to:

Thread 1:
    at com.wolfssl.provider.jsse.WolfSSLSocket$WolfSSLOutputStream.close(WolfSSLSocket.java:2618)
    - waiting to lock <0x00000000f42874f8> (a com.wolfssl.provider.jsse.WolfSSLSocket$WolfSSLOutputStream)
    at com.wolfssl.provider.jsse.WolfSSLSocket.close(WolfSSLSocket.java:1951)
    - locked <0x00000000f4287588> (a java.lang.Object)
    - locked <0x00000000f4287578> (a java.lang.Object)
    - locked <0x00000000f4287518> (a com.wolfssl.provider.jsse.WolfSSLSocket)

Thread 2:
    at com.wolfssl.provider.jsse.WolfSSLSocket$WolfSSLOutputStream.write(WolfSSLSocket.java:2684)
    - waiting to lock <0x00000000f4287588> (a java.lang.Object)
    - locked <0x00000000f42874f8> (a com.wolfssl.provider.jsse.WolfSSLSocket$WolfSSLOutputStream)

Similar deadlock was observed when running against SunJSSE test SSLSocketImpl/AsyncSSLSocketClose.java:

Java stack information for the threads listed above:
===================================================
"Thread-1":
    at java.net.Socket.getSoTimeout(Socket.java:1174)
    - waiting to lock <0x000000066bdd0908> (a com.wolfssl.provider.jsse.WolfSSLSocket)
    at com.wolfssl.provider.jsse.WolfSSLSocket.getSoTimeout(WolfSSLSocket.java:1860)
    at com.wolfssl.provider.jsse.WolfSSLSocket$WolfSSLOutputStream.write(WolfSSLSocket.java:2869)
    - locked <0x000000066c4bf330> (a com.wolfssl.provider.jsse.WolfSSLSocket$WolfSSLOutputStream)
    at com.wolfssl.provider.jsse.WolfSSLSocket$WolfSSLOutputStream.write(WolfSSLSocket.java:2793)
    at AsyncSSLSocketClose.run(AsyncSSLSocketClose.java:124)
    at java.lang.Thread.run(Thread.java:750)
"MainThread":
    at com.wolfssl.provider.jsse.WolfSSLSocket$WolfSSLOutputStream.close(WolfSSLSocket.java:2739)
    - waiting to lock <0x000000066c4bf330> (a com.wolfssl.provider.jsse.WolfSSLSocket$WolfSSLOutputStream)
    at com.wolfssl.provider.jsse.WolfSSLSocket.close(WolfSSLSocket.java:2074)
    - locked <0x000000066bdd0908> (a com.wolfssl.provider.jsse.WolfSSLSocket)
    at AsyncSSLSocketClose.<init>(AsyncSSLSocketClose.java:95)
    at AsyncSSLSocketClose.main(AsyncSSLSocketClose.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.javatest.regtest.agent.MainWrapper$MainThread.run(MainWrapper.java:127)
    at java.lang.Thread.run(Thread.java:750)

Found 1 deadlock.

@JacobBarthelmeh JacobBarthelmeh merged commit fa2a5af into wolfSSL:master Nov 6, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants