1

I'm trying to send an array of data as an rpc reply using golang's built-in net/rpc server and client and the net/rpc/jsonrpc codec. But I'm running into some trouble.

The data I'm sending is around 48 bytes, and the client will just hang in client.Call.

I've made a playground that replicates the problem: https://go.dev/play/p/_IQ9SF7TSdc

If you change the constant "N" in the above program to 5, things work as expected!

Another playground shows how the issue seems to crop up only when the slice/array in question exceeds 49 bytes: https://go.dev/play/p/R8CQa0mv7vB

Does anyone know what might be the issue? Golang's tests for the array and slice data types are not exactly designed for "large" arrays in mind. Thanks in advance.

9
  • 1
    Is there any reason to use "unixpacket" instead of "unix"? I conjure, your issue will be resolve once you move to "normal" bytestream-oriented connections over the Unix-domain sockets. Commented Nov 8, 2022 at 15:28
  • 1
    From the socket manpage: SOCK_SEQPACKET: Provides a sequenced, reliable, two-way connection-based data transmission path for datagrams of fixed maximum length; a consumer is required to read an entire packet with each input system call. That is of course not going to work for a service which is not designed to use it, and is expecting a stream protocol. Commented Nov 8, 2022 at 15:32
  • @kostix thank you so much! that did the trick. I found this answer explaining how the network type affects the underlying socket call. But I'd be interested to know why the limit is short on the unixpackets. Anyways you have my deepest thanks. Commented Nov 8, 2022 at 15:37
  • Ah thanks @JimB, i didn't know rpcs where supposed to be over a stream. My thanks. Commented Nov 8, 2022 at 15:39
  • 1
    The deadlock is only a symptom caused by your particular example. Most people wouldn't be implementing both sides of the connection in the same process (except for toy examples), and even then may still have network loops which could technically proceed and won't trigger deadlock detection. The deadlock isn't really relevant, the stream is corrupted causing the sender and/or receiver to hang. Commented Nov 8, 2022 at 18:41

1 Answer 1

1

On the line where the listener is set up:

listener, err := net.ListenUnix("unixpacket", &net.UnixAddr{RPCPath, "unixpacket"})

Don't use unixpacket. It corresponds to the underlying SOCK_SEQPACKET which is not a stream protocol. Likely large files were separated into packets in a way the receiver was not able to process. Use unix instead, which corresponds to SOCK_STREAM. See this SO post for more.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.