gorpcpacketunix-socketjson-rpc

Why sends of "large" array/slice using net/rpc/jsonrpc codec over unix socket connection hang?


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.


Solution

  • 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.