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

huangapple go评论69阅读模式
英文:

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

问题

我正在尝试使用Go语言的内置net/rpc服务器和客户端以及net/rpc/jsonrpc编解码器将数据数组作为RPC回复发送,但遇到了一些问题。

我发送的数据大约有48字节,但客户端在client.Call处卡住了。

我创建了一个复制该问题的playground:
https://go.dev/play/p/_IQ9SF7TSdc

如果你将上述程序中的常量"N"更改为5,一切都会按预期工作!

另一个playground显示了只有在所讨论的切片/数组超过49字节时才会出现问题:
https://go.dev/play/p/R8CQa0mv7vB

有人知道可能是什么问题吗?Go语言对数组和切片数据类型的测试并不完全考虑到"大型"数组。提前感谢。

英文:

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.

答案1

得分: 1

在设置监听器的那一行代码上:

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

不要使用 unixpacket。它对应的是底层的 SOCK_SEQPACKET,而不是流协议。可能会将大文件分成数据包,接收方无法处理。请改用 unix,它对应的是 SOCK_STREAM。
详见这个 Stack Overflow 帖子

英文:

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.

huangapple
  • 本文由 发表于 2022年11月8日 23:21:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/74363129.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定