Repository navigation
ZOOKEEPER-5123: (C client) Broadcast completion of auth can return ZOK for rejected credentials - #2498
ZOOKEEPER-5123: (C client) Broadcast completion of auth can return ZOK for rejected credentials#2498apurtell wants to merge 2 commits into
Conversation
anmolnar
left a comment
There was a problem hiding this comment.
AI-assisted review on behalf of @anmolnar
Thanks for this. I traced the change against zookeeper.c and the server's processPacket, and it looks correct to me: the server answers each SetAuth frame once and in order, the pending FIFO and the send queue are updated together under the auth lock at the same end, front insertion at session establishment cannot land ahead of a partly written buffer, and after a rejection the remaining pending completions are finished with ZAUTHFAILED through handle_error. I also walked the two zoo_add_auth races with the I/O thread (around finalize_session_establishment and around cleanup) and both end with one frame per credential. I did not build or run the tests.
A few points, none blocking:
- The reconnect path is not covered.
testResentCredentialDoesNotCompleteNewRequestnever disconnects, so the loop insend_auth_infothat hands pending completions back,remove_auth_frames, and front insertion with more than one stored credential are all unexercised. Could you add (a) two credentials stored beforeconnect(), one accepted and one rejected, asserting each completion gets its own result, and (b) a disconnect and reconnect with replies held, then a newzoo_add_auth, asserting the resend's reply does not complete it? testConcurrentAddAuthSendsEachCredentialpasses NULL completions and ignores the return ofzoo_add_auth. A completion per call, asserted to run once withZOK, would also check matching under concurrency.zookeeper.hsays the completion receivesZOKorZAUTHFAILED. A request that is still pending when an earlier credential is rejected now getsZAUTHFAILED, and on a disconnect it gets the connection-loss code while the credential is kept and resent without a completion. The second part is not new, but a sentence in the header would make the contract clear.- Small:
zoo_add_authstill does not calladaptor_send_queuewhen connected, so the frame waits for the I/O thread's next wake-up (same on master); aZSYSTEMERRORfromsend_info_packetis returned asZMARSHALLINGERROR; andauth_info.stateis now write-only.
…K for rejected credentials When the C client received a reply to a SetAuth request, auth_completion_func ran every pending callback with the status of that one reply without checking which credential the reply belongs to. The client also put SetAuth frames at the front of the send queue, so frames from back-to-back calls went out in reverse order. There were additional related problems on the same path: - Credentials that the client sends again during a reconnect could complete newly issued zoo_add_auth calls before the server checked them. - An auth reply on a handle with no credentials dereferenced a NULL list and crashed the I/O thread. - Concurrent zoo_add_auth calls could both send the last credential in the list. - If a frame could not be queued zoo_add_auth would return an error but leave the callback registered. Each handle now keeps a FIFO of pending SetAuth frames in the order of frames on the wire. Each reply completes only the entry at the head. Related fixes: - An auth reply with no pending frame is logged and ignored. Before, it dereferenced a NULL credential list. - zoo_add_auth holds the auth lock while it queues the frame of its own credential. Concurrent calls no longer send the tail credential twice. The frame goes to the end of the send queue. - zoo_add_auth checks its allocations. If the frame cannot be queued, the credential is not added and its completion never runs. - zoo_add_auth no longer sends a frame in ZOO_ASSOCIATING_STATE. Session establishment sends the credential with its completion. Adds the Zookeeper_authCompletion suite in tests/TestAuthCompletion.cc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… contract Address review feedback: - Add tests for two stored credentials with separate results, for a reconnect resend that does not complete a new request, and for zoo_add_auth on the I/O thread during session establishment. The last test drives the code that takes back pending completions and drops queued SetAuth frames. - Give each call in the concurrency test a completion, and check that it runs once with ZOK and that zoo_add_auth returns ZOK. - Document in zookeeper.h which result a pending completion receives after an earlier rejection or a disconnect. - Send the frame at once when connected, as the other async calls do. - Return ZSYSTEMERROR from zoo_add_auth as itself. - Remove the write-only auth_info.state field. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6235222 to
86f63df
Compare
|
Reply from Claude Code (an AI assistant), on behalf of @apurtell. Thanks @anmolnar. Your review points are addressed in 86f63df. I also rebased the branch onto current master.
The ST and MT suites pass. I applied #2510 locally for the OpenSSL certificate failures. |
When the C client received a reply to a SetAuth request, auth_completion_func ran every pending callback with the status of that one reply without checking which credential the reply belongs to. The client also put SetAuth frames at the front of the send queue, so frames from back-to-back calls went out in reverse order.
There were additional related problems on the same path:
Each handle now keeps a FIFO of pending SetAuth frames in the order of frames on the wire. Each reply completes only the entry at the head.
Related fixes:
Adds the Zookeeper_authCompletion suite in tests/TestAuthCompletion.cc.