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

[Bug] java.net.Socket::isConnected behaves differently from openJDK #437

Closed
luoxiner opened this issue Nov 11, 2022 · 2 comments
Closed
Assignees

Comments

@luoxiner
Copy link

Description
the method java.net.Socket::isConnected behaves differently from openJDK
this different behavior cause the java.net.Socket::getRemoteSocketAddress returns
an unexpected null value.

the openJDK specification of java.net.Socket::isConnected is
Returns the connection state of the socket.
Note: Closing a socket doesn't clear its connection state, which means this method will return true for a closed socket (see isClosed()) if it was successfuly connected prior to being closed.
Returns:
true if the socket was successfuly connected to a server
Since:
1.4

public boolean isConnected() {
    if (WispEngine.transparentWispSwitch())
        return asyncImpl.isConnected(); // return the SocketChannelImpl.isConnected

    // Before 1.3 Sockets were always connected during creation
    return connected || oldImpl;
}

Expected behavior
return the same value as openJDk

JDK version
openjdk version "1.8.0_322"
OpenJDK Runtime Environment (Alibaba Dragonwell 8.10.11) (build 1.8.0_322-b01)
OpenJDK 64-Bit Server VM (Alibaba Dragonwell 8.10.11) (build 25.322-b01, mixed mode)

@luoxiner luoxiner changed the title [Bug] A new bug [Bug] java.net.Socket::isConnected behaves differently from openJDK Nov 11, 2022
@zhengxiaolinX
Copy link
Contributor

Thanks a lot for reporting this! It is indeed a discordance, and we are working on that.

zhengxiaolinX added a commit that referenced this issue Nov 11, 2022
…urning result

Summary: Socket.connect() in Wisp's implemention, uses nio SocketChannel's logic to prevent blocking when Socket is used. However, OpenJDK's isConnected() returns true after successfully connecting even if the socket gets closed. This will cause break accordance so we shall fix this.

Test Plan: newly-added ServerSocketConnectionTest.java

Reviewed-by: D-D-H

Issue: #437
@zhengxiaolinX
Copy link
Contributor

Done as completed.

zhengxiaolinX added a commit that referenced this issue Nov 16, 2022
…urning result for ServerSocket.accept()

Summary: Same as #438: we have another path ServerSocket.accept() to cover.

Test Plan: ServerSocketConnectionTest.java

Reviewed-by: D-D-H, yuleil

Issue: #437
zhengxiaolinX added a commit that referenced this issue Nov 16, 2022
… usage

Summary: JavaNetSocketAccess is used in WispServerSocketImpl.java, but the former one's initialization is in Socket.java. This underlying problem shall be fixed.

Test Plan: ServerSocketConnectionTest.java

Reviewed-by: D-D-H, yuleil

Issue: #437
zhengxiaolinX added a commit that referenced this issue Nov 18, 2022
… usage

Summary: JavaNetSocketAccess is used in WispServerSocketImpl.java, but the former one's initialization is in Socket.java. This underlying problem shall be fixed.

Test Plan: ServerSocketConnectionTest.java

Reviewed-by: D-D-H, yuleil

Issue: #437
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

No branches or pull requests

2 participants