[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-5123?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

ASF GitHub Bot updated ZOOKEEPER-5123:
--------------------------------------
    Labels: pull-request-available  (was: )

> (C client) Broadcast completion of auth can return ZOK for rejected 
> credentials
> -------------------------------------------------------------------------------
>
>                 Key: ZOOKEEPER-5123
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-5123
>             Project: ZooKeeper
>          Issue Type: Bug
>          Components: c client
>            Reporter: Andrew Kyle Purtell
>            Assignee: Andrew Kyle Purtell
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> When the C client receives a reply to a SetAuth request, 
> {{auth_completion_func}} runs every pending {{zoo_add_auth}} callback with 
> the status of that one reply. It never checks which credential the reply 
> belongs to. The client also puts SetAuth frames at the front of the send 
> queue, so frames from back-to-back calls go out in reverse order.
> Suppose an application adds an invalid credential and then a valid one. The 
> server accepts the valid one first, and both callbacks receive {{{}ZOK{}}}. 
> The server then rejects the invalid credential and closes the connection. By 
> that time the application has already been told the rejected credential 
> succeeded, and it may act on that.
> There are related problems on the same path:
>  * Credentials that the client sends again during a reconnect can complete 
> newly issued {{zoo_add_auth}} calls before the server has checked them.
>  * An auth reply on a handle with no credentials dereferences a NULL list and 
> crashes the I/O thread.
>  * Concurrent {{zoo_add_auth}} calls can both send the last credential in the 
> list, so one thread's credential is never sent.
>  * If the frame cannot be queued, {{zoo_add_auth}} returns an error but 
> leaves the callback registered.
> The fix is to give each handle a FIFO of SetAuth frames waiting for a reply, 
> kept in the same order as the frames on the wire. The server processes 
> SetAuth packets inline and replies in the order it receives them. So each 
> reply completes only the oldest pending entry and updates only that entry's 
> credential. A rejection still moves the handle to 
> {{{}ZOO_AUTH_FAILED_STATE{}}}, and the teardown fails any callbacks still 
> pending.
> The fix also address the related problems:
>  * An auth reply with no pending frame is logged and ignored.
>  * {{zoo_add_auth}} holds the auth lock while it queues its own credential's 
> frame, and it checks its memory allocations.
>  * {{zoo_add_auth}} now adds its frame to the end of the send queue, as the 
> Java client does.
>  * {{zoo_add_auth}} no longer sends a frame while the session is still being 
> established; the credential is sent once the session is ready. Before, that 
> path sent the credential twice.
> A new {{Zookeeper_authCompletion}} test suite covers these cases.
> The public API and ABI are unchanged.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to