Skip to content

ZOOKEEPER-5125 (C client) zoo_multi error handling crashes, misreads results, and hangs - #2500

Open
apurtell wants to merge 1 commit into
apache:masterfrom
apurtell:ZOOKEEPER-5125
Open

apurtell wants to merge 1 commit into
apache:masterfrom
apurtell:ZOOKEEPER-5125

Conversation

@apurtell

@apurtell apurtell commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

The C client's multi() path has several related defects.

When a synchronous zoo_multi() call fails, the err fields of the zoo_op_result_t array stay uninitialized, so an application might mistake a failed sub-operation as a success. NULL ops or results arrays will crash the client instead of returning an error. On an expired or unrecoverable handle, the client still queues requests, so a synchronous call can block forever, for example a zero count zoo_multi().

Inside a multi op handling the server answers a container create with a Create2Response, which holds a path and a stat. However the client decodes it as a CreateResponse which doesn't know about the stat, so every result after it will be decoded in a misaligned manner, essentially reading garbage.

The fix fills every result slot with the failure code on all failure paths, and returns ZBADARGUMENTS for NULL arrays. New requests on an unrecoverable handle are refused at once. Each sub-result is decoded correctly. A reply with more or fewer results than operations returns ZMARSHALLINGERROR instead of crashing the application.

New mock server tests Zookeeper_multiFailure and real server test Zookeeper_multi::testCreateContainer cover these cases.

…zed, desync on container creates, abort on header-only errors, and hang on dead handles

Fix a group of related defects in the C client multi-op path:

- Synchronous zoo_multi() failures left the err fields of zoo_op_result_t
  uninitialized. Fill every result slot with the failure code when the
  multi fails at call time (validation, send failure, closed or
  unrecoverable handle) and when a pending multi is drained on
  connection loss or session expiry.
- A container create inside a multi gets a Create2Response (path and
  stat). The client decoded it as a CreateResponse, which left the stat
  in the stream and misaligned all following sub-results. Decode the
  record by its wire type.
- A multi reply with an error in its header (for example ZNOTREADONLY)
  has no body. The synchronous path tried to decode it and hit
  assert(entry). Fail every sub-operation with the header error instead.
  Treat replies with more or fewer sub-results than operations as
  ZMARSHALLINGERROR instead of crashing.
- do_add_completion() queued requests on an unrecoverable handle, where
  no teardown drains them. A synchronous caller, for example a
  zero-count zoo_multi() on an expired session, waited forever. Refuse
  the request instead.
- zoo_amulti() dereferenced NULL ops or results arrays. Return
  ZBADARGUMENTS.

Add Zookeeper_multiFailure mock-server tests and a real-server
Zookeeper_multi::testCreateContainer test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant