-
Notifications
You must be signed in to change notification settings - Fork 74
Fix authentication mechanism #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
As of now, during the authentication process, we, more or less, do the following: - Send an authentication request - Put a future that will be resolved after the authentication request completes to the pending connections that performs client-side authentication logic (ConnectionManager#on_auth) - Return the future The problem is that, through unlucky timing, we might perform the authentication logic before putting the future to the pending connections map. Such as, - Clients initiates get_or_connect in the main thread during startup - We send the authentication request in the main thread - Before we return the invocation future, and add a callback to it, Python schedules the reactor thread, we write the request to wire, and get back the response. - Python schedules the main thread again, it is now trying to add a callback to a completed future. Since it is completed, it executes the authentication logic immediately. One of the steps of the client side authentication logic is to remove the connection from the pending connections map. Since the future is not put into the map yet, nothing is removed. - We then add this future to the pending connections map, but since it is already completed, no one is going to remove it from the pending connections map. - During the shutdown, we see an unexpected entry in the pending connections map and fail. To solve this, we put a future directly into the pending connections and perform the logic afterward.
What is a reactor thread |
|
This is so interesting :) |
yeah this is what I thought as well immediately after reading the problem |
| else: | ||
| e = response.exception() | ||
| # This will set the exception for the pending connection future | ||
| connection.close("Failed to authenticate connection", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this close calls cause self._authenticate(connection) call to raise exception. Is this right?
|
Closing this in favor of #388 |
As of now, during the authentication process, we, more or less, do the
following:
to the pending connections that performs client-side authentication logic
(ConnectionManager#on_auth)
The problem is that, through unlucky timing, we might perform the
authentication logic before putting the future to the pending connections
map. Such as,
Python schedules the reactor thread, we write the request to wire,
and get back the response.
a callback to a completed future. Since it is completed, it executes
the authentication logic immediately. One of the steps of the client
side authentication logic is to remove the connection from the pending
connections map. Since the future is not put into the map yet, nothing
is removed.
it is already completed, no one is going to remove it from the
pending connections map.
connections map and fail.
To solve this, we put a future directly into the pending connections
and perform the logic afterward.
Closes #378