Skip to content

spdk: do not half-close the connection before reading the response - #77

Merged
artek-koltun merged 1 commit into
opiproject:mainfrom
tfrankow-intel:fix/jsonrpc-avoid-write-half-close
Jul 10, 2026
Merged

spdk: do not half-close the connection before reading the response#77
artek-koltun merged 1 commit into
opiproject:mainfrom
tfrankow-intel:fix/jsonrpc-avoid-write-half-close

Conversation

@tfrankow-intel

Copy link
Copy Markdown
Contributor

Client.communicate() called conn.CloseWrite() immediately after writing the request and before reading the reply, half-closing the write side of the socket.

SPDK's JSON-RPC server marks conn->closed when it sees the client's write-half EOF. Historically that was harmless because jsonrpc_server_send_response queued the reply regardless. SPDK commit 274643bf27f2d8ac04d8326e90c17c62cd31a614 ("lib/jsonrpc: fix memory leak on closed connection") changed that: send_response now checks conn->closed and, when set, drops the reply instead of queuing it, logging "attempt to send response on closed connection".

For asynchronous RPCs whose reply is produced later by a poller (e.g. nvmf_create_transport, bdev_nvme_attach_controller), the client's half-close is processed before the reply is ready, so with that change the server drops the reply and the client reads a spurious EOF even though the operation succeeded on the target.

A JSON-RPC request is self-delimiting (a single complete JSON object), so half-closing the write side is unnecessary to frame the request. Remove the CloseWrite and keep the connection fully open until the single response is read.

@tfrankow-intel
tfrankow-intel requested a review from a team as a code owner July 9, 2026 17:53

@artek-koltun artek-koltun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, we probably need this first: #76

@tfrankow-intel
tfrankow-intel force-pushed the fix/jsonrpc-avoid-write-half-close branch from 578e5de to 4bde8c9 Compare July 10, 2026 09:18
Client.communicate() called conn.CloseWrite() immediately after writing
the request and before reading the reply, half-closing the write side
of the socket.

SPDK's JSON-RPC server marks conn->closed when it sees the client's
write-half EOF. Historically that was harmless because
jsonrpc_server_send_response queued the reply regardless. SPDK commit
274643bf27f2d8ac04d8326e90c17c62cd31a614 ("lib/jsonrpc: fix memory leak
on closed connection") changed that: send_response now checks
conn->closed and, when set, drops the reply instead of queuing it,
logging "attempt to send response on closed connection".

For asynchronous RPCs whose reply is produced later by a poller
(e.g. nvmf_create_transport, bdev_nvme_attach_controller), the client's
half-close is processed before the reply is ready, so with that change
the server drops the reply and the client reads a spurious EOF even
though the operation succeeded on the target.

A JSON-RPC request is self-delimiting (a single complete JSON object),
so half-closing the write side is unnecessary to frame the request.
Remove the CloseWrite and keep the connection fully open until the
single response is read.

Signed-off-by: Frankowski, Tomasz <tomasz.frankowski@intel.com>
@tfrankow-intel
tfrankow-intel force-pushed the fix/jsonrpc-avoid-write-half-close branch from 4bde8c9 to 9663d8a Compare July 10, 2026 12:05
@artek-koltun
artek-koltun merged commit de3e047 into opiproject:main Jul 10, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants