Environment
- CP version: v0.9.4 (
f925e5f6)
Description
The control protocol is newline-delimited JSON over a unix stream socket (docs/REFACTOR-CPCTL.md §1). The reference client, cpgolib/cpworker/unix_client.go, appends \n to each request. A stream socket has no message boundaries, so the server has to split requests on the newline. cpworker instead treats each read() as a single request.
As a result:
- A request split across several writes gets no reply. This happens with a slow or large write, or with any client that writes in pieces.
- Only the first of several requests in one write is answered; the others are dropped. This includes
{"version":"v1"}\n{"command":"ping"}\n sent together.
Today's Go client happens to write one line and wait for the reply, which hides the problem. Any other client, or a larger request, runs into it.
Steps to reproduce
The failing tests are in TestControlProtocol, cpworker/tests/integration/control_protocol_test.go (branch feat/verification-coverage):
request_split_across_writes: no reply within 5 s.
pipelined_requests_in_one_write: reply 2 of 3 is missing.
handshake_in_the_same_write_as_first_request: reply 2 is missing.
Expected
Buffer each connection's input and answer every complete line, in order.
Actual
Each read() is treated as one request.
中文原文
测试环境
问题描述
控制协议是 unix 流 socket 上的换行分隔 JSON(docs/REFACTOR-CPCTL.md §1;参考客户端 cpgolib/cpworker/unix_client.go 在每个请求后追加 \n)。流 socket 没有消息边界,服务端应按换行切分;cpworker 却把每次 read() 当作一条完整请求:
- 拆成多次写入的请求得不到应答(慢速/大请求或分段写入的客户端)。
- 一次写入多条请求只应答第一条,其余丢弃,包括同时发送的
{"version":"v1"}\n{"command":"ping"}\n。
现有 Go 客户端恰好"写一行、等应答",掩盖了问题;其他客户端或更大的请求会遇到。
复现
feat/verification-coverage 分支 cpworker/tests/integration/control_protocol_test.go 的 TestControlProtocol:
request_split_across_writes:5 秒内无应答。
pipelined_requests_in_one_write:3 个应答缺第 2 个。
handshake_in_the_same_write_as_first_request:缺第 2 个应答。
期望
按连接缓冲输入,按顺序应答每一整行。
实际
每次 read() 当作一条请求。
Environment
f925e5f6)Description
The control protocol is newline-delimited JSON over a unix stream socket (
docs/REFACTOR-CPCTL.md§1). The reference client,cpgolib/cpworker/unix_client.go, appends\nto each request. A stream socket has no message boundaries, so the server has to split requests on the newline. cpworker instead treats eachread()as a single request.As a result:
{"version":"v1"}\n{"command":"ping"}\nsent together.Today's Go client happens to write one line and wait for the reply, which hides the problem. Any other client, or a larger request, runs into it.
Steps to reproduce
The failing tests are in
TestControlProtocol,cpworker/tests/integration/control_protocol_test.go(branchfeat/verification-coverage):request_split_across_writes: no reply within 5 s.pipelined_requests_in_one_write: reply 2 of 3 is missing.handshake_in_the_same_write_as_first_request: reply 2 is missing.Expected
Buffer each connection's input and answer every complete line, in order.
Actual
Each
read()is treated as one request.中文原文
测试环境
f925e5f6)问题描述
控制协议是 unix 流 socket 上的换行分隔 JSON(
docs/REFACTOR-CPCTL.md§1;参考客户端cpgolib/cpworker/unix_client.go在每个请求后追加\n)。流 socket 没有消息边界,服务端应按换行切分;cpworker 却把每次read()当作一条完整请求:{"version":"v1"}\n{"command":"ping"}\n。现有 Go 客户端恰好"写一行、等应答",掩盖了问题;其他客户端或更大的请求会遇到。
复现
feat/verification-coverage分支cpworker/tests/integration/control_protocol_test.go的TestControlProtocol:request_split_across_writes:5 秒内无应答。pipelined_requests_in_one_write:3 个应答缺第 2 个。handshake_in_the_same_write_as_first_request:缺第 2 个应答。期望
按连接缓冲输入,按顺序应答每一整行。
实际
每次
read()当作一条请求。