[ 
https://issues.apache.org/jira/browse/ZOOKEEPER-4885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18133755#comment-18133755
 ] 

Andor Molnar commented on ZOOKEEPER-4885:
-----------------------------------------

*Claude's comment*

Thanks for the detailed report, [~JIRAUSER298666]. I went through the client 
code on master and I think the behaviour is real, but narrower than "the client 
never recovers". Let me summarize what actually happens and where I think the 
fix belongs.

*1. The fail-open on LoginException is intentional.*
When \{{new ZooKeeperSaslClient(...)}} throws a \{{LoginException}} in 
\{{ClientCnxn.SendThread#startConnect}}, the client logs "Will continue 
connection to Zookeeper server without SASL authentication", queues a non-fatal 
\{{AuthFailed}} event and sets \{{saslLoginFailed = true}}. This is by design 
(ZOOKEEPER-2139 / ZOOKEEPER-2323): clients that don't need SASL, or only need 
open znodes, keep working. Unlike an AuthFailed coming from the server-side 
SASL handshake, this one does *not* close the handle.

*2. Login is retried on every reconnect.*
{\{startConnect}} resets \{{saslLoginFailed}} and constructs a fresh 
\{{ZooKeeperSaslClient}} on every connection attempt. Because the failed login 
never populated \{{loginRef}}, a new \{{Login}} is attempted each time. SASL 
auth is per-connection on the server, so the next connection after the KDC is 
back authenticates normally and the same session keeps working.
So the client does recover, but only on its next reconnect. If the 
unauthenticated connection stays healthy, nothing ever triggers a reconnect, 
and that's the stuck state you're seeing.

*3. When this can happen.*
Once a \{{Login}} has succeeded it is cached per handle and the refresh thread 
renews the TGT, so a KDC outage later in the handle's life does not lead here. 
The stuck state requires the handle to be *created* (or to reconnect for the 
first time) while the KDC is unreachable. That's exactly the case when Curator 
rebuilds the client after session expiry.

*4. The InvalidACL storm is a Curator issue.*
The \{{InvalidACL}} is expected: with an \{{auth}}-scheme ACL and no 
authenticated ids on the connection, \{{PrepRequestProcessor.fixupACL}} rejects 
the create. The CPU / log flooding on the server comes from 
\{{PersistentEphemeralNode}}'s background callback, which treats every result 
other than \{{OK}}/\{{NODEEXISTS}} as "retry immediately, without backoff". Any 
persistent error would cause the same tight loop, not only auth. That should be 
raised with Curator, independently of what we do here.

*Workaround today:* treat \{{KeeperState.AuthFailed}} as a signal to close and 
recreate the handle (which is what you proposed for HiveServer2). We should 
probably document that a non-fatal AuthFailed means "connected, but not 
authenticated".

*Possible improvement on the ZK side* (opt-in, so the non-SASL fail-open keeps 
working):
* *Fail closed when SASL is explicitly configured:* treat the 
\{{LoginException}} as a failed connection attempt, so the client stays in 
CONNECTING and retries with backoff instead of connecting unauthenticated. 
Simple and predictable, but the application sees a disconnect for the duration 
of the KDC outage.
* *Background re-login + reconnect:* while \{{saslLoginFailed}} is true, 
periodically retry \{{Login}} with backoff. On success, drop the current 
connection so \{{startConnect}} runs again and authenticates. The session (and 
its ephemerals) survives. This is closest to the "automatic recovery" asked for 
in the title.

I lean towards the second option. Either way we'd need a MiniKdc-based test 
that starts the client with an unreachable KDC, restores it, and asserts the 
client ends up SaslAuthenticated without any application involvement.

Would you be interested in working on a patch? I'm happy to review.

> Can Non-SASL-Clients automatically recover with the recovery of kerberos 
> communication?
> ---------------------------------------------------------------------------------------
>
>                 Key: ZOOKEEPER-4885
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-4885
>             Project: ZooKeeper
>          Issue Type: Improvement
>    Affects Versions: 3.4.14, 3.6.4, 3.9.3
>            Reporter: Xin Chen
>            Priority: Major
>
> About  ZOOKEEPER-2139 & ZOOKEEPER-2323, it just avoids ZooKeeper clients into 
> infinite AuthFailedException. Noauth Exception still exists! 
> LoginException was thrown through each login, but at this point, a zkclient 
> without Kerberos SASL authentication was created. Non SASL Znodes can be 
> operated on in the future. However, when Kerberos recovers from network 
> disconnections and other anomalies, the previously created zkclient without 
> SASL authentication is still being used without rebuilding the login or 
> recreating a saslclient. If it is used to operate on ACL Znodes at this time, 
> an error will always be reported: 
> {code:java}
> KeeperErrorCode = NoAuth for /zookeeper
> or
> KeeperErrorCode = AuthFailed for /zookeeper
> or
> KeeperErrorCode = InvalidACL for /zookeeper{code}
> Isn't this a question that should be considered?  And I also met this issue 
> in ZK-3.6.4,It seems that this issue has not been considered in the updated 
> version. 



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

Reply via email to