-
Notifications
You must be signed in to change notification settings - Fork 71
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
UnixDomainSocket connection returns error from server #528
Comments
Hi Hitesh, Thanks for your bug report. That is indeed weird and not something I have seen in the past! A few ideas:
On the client side, in Java, after you connect do you send anything? Connections to the socket are meant to be short-lived, in Rust and Go we do the following for each operation the client wants to perform:
It might be the case that we totally omitted this from our docs or something is not clear! |
Thanks for the quick response. Please find attached the error that is immediately coming after SocketChannel.open(socketAddress). The connect socket itself is giving an error. Also, there is no timeout setting for java UnixDomainSockets and therefore cannot set it in the SocketChannel. However, have increased the timeout in the server to 1200.
//Trace at Server
Below is the code that is used.
The java console gives the following
|
I was able to reproduce the bug starting Parsec from the quickstart guide and using the following Java file (improved from the HelloWorld basic file since I have not done Java in a long long time): root@d55705680706:/tmp/parsec_test# cat HelloWorldApp.java
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.net.UnixDomainSocketAddress;
import java.nio.file.Path;
import java.io.IOException;
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
Path socketFile = Path.of("/tmp/quickstart-0.7.0-linux_x86/parsec.sock");
UnixDomainSocketAddress socketAddress = UnixDomainSocketAddress.of(socketFile);
try {
SocketChannel clientChannel = SocketChannel.open(socketAddress);
if (clientChannel.isConnected()) {
System.out.println("Channel open: " + clientChannel.isOpen());
System.out.println("Channel blocking: " + clientChannel.isBlocking());
System.out.println("Socket Connected: " + clientChannel.isConnected());
System.out.println("Is Connection Pending: " + clientChannel.isConnectionPending());
ByteBuffer buff = ByteBuffer.allocate(100);
int bytes_read = clientChannel.read(buff);
bytes_read += clientChannel.read(buff);
System.out.println("bytes read: " + bytes_read);
buff.rewind();
while (buff.hasRemaining()) {
System.out.print(" " + buff.get());
}
System.out.println(" ");
}
}
catch(IOException e) {
e.printStackTrace();
}
}
} I see the exact same error message and bytes returned. This is a Parsec error message response with empty bodies, the Ping opcode and the Communication Error status. However, I can see a difference if I change the timeout on Parsec side. For example setting a 5 seconds timeout (
and then exactly 5 seconds after:
Which lets me think that this is a timeout issue: Parsec is waiting for the timeout time that some data is sent over the socket by the client and after that time sends back an error response. Are you experiencing the same if you increase the timeout on Parsec side to 5, 10 seconds? Or does it still immediately fail? |
Thanks Hugues. That is a good observation. You are right, I am also able to see the error after 5 seconds timeout. |
I tried that as well and observed the same behaviour until I remembered I need to call /**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.net.UnixDomainSocketAddress;
import java.nio.file.Path;
import java.io.IOException;
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
Path socketFile = Path.of("/tmp/quickstart-0.7.0-linux_x86/parsec.sock");
UnixDomainSocketAddress socketAddress = UnixDomainSocketAddress.of(socketFile);
try {
SocketChannel clientChannel = SocketChannel.open(socketAddress);
if (clientChannel.isConnected()) {
System.out.println("Channel open: " + clientChannel.isOpen());
System.out.println("Channel blocking: " + clientChannel.isBlocking());
System.out.println("Socket Connected: " + clientChannel.isConnected());
System.out.println("Is Connection Pending: " + clientChannel.isConnectionPending());
ByteBuffer write_buff = ByteBuffer.allocate(4);
//write_buff.put((byte)0x10);
write_buff.put((byte)0x11);
write_buff.put((byte)0xA7);
write_buff.put((byte)0xC0);
write_buff.put((byte)0x5E);
write_buff.rewind();
int bytes_written = clientChannel.write(write_buff);
System.out.println("bytes written: " + bytes_written);
ByteBuffer read_buff = ByteBuffer.allocate(100);
int bytes_read = clientChannel.read(read_buff);
bytes_read += clientChannel.read(read_buff);
System.out.println("bytes read: " + bytes_read);
read_buff.rewind();
while (read_buff.hasRemaining()) {
System.out.print(" " + read_buff.get());
}
System.out.println(" ");
}
}
catch(IOException e) {
e.printStackTrace();
}
}
} Console client side:
On the Parsec side:
Did you think about rewinding yourself? Do you have somehow similar code? |
Thanks Hugues. Yes, I had missed rewind over several trials. :-) After increasing the timeout, it seems to be sending the response properly. Please find below the code that I am using and the console output. Thanks & Regards.
Console Output:
On Parsec side:
In case of wrong Magic number:
On Parsec side:
|
Nice, perfect! Glad I was able to help 😃 |
Hi,
While trying to connect to PARSEC server using Java 16 java.net.UnixDomainSocketAddress, PARSEC server returns an error as soon as the client is connected to the server. This is without even sending any data to the SocketChannel. Also it returns error status 15 ConnectionError - Generic input/output error. Returned buffer is
10 a7 c0 5e 1e 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 f 0 0 0
Below are the error details.
Best regards,
Hitesh
The text was updated successfully, but these errors were encountered: