-
Notifications
You must be signed in to change notification settings - Fork 73
Skip closing an initializing connection #42
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
|
@ibuildthecloud and @brandond could you review this? (I can't add reviewers) I've tried to verify that this change doesn't cause a regression to the three related issues mentioned above and seems to be working fine, but I could be missing something. |
|
See the comment at https://github.com/rancher/dynamiclistener/pull/28/files#r468192991 as to why I moved it. If you can confirm that this doesn't regress the issue that moving it fixed then I'm good. |
|
Is the |
|
You might also be using dynamiclistener in an environment where you don't need to or shouldn't close existing connections when the cert changes? |
That's what seems to be happening, so moving Lines 254 to 256 in 94e2249
Based on rancher/rancher#25386 closing existing connections is intentional and necessary for websockets to work but I'm not sure if it's needed otherwise. |
7b0f351 to
bd2fd11
Compare
|
There's nowhere to move the dynamicListener.wrap to that would help because the problem occurs during the dynamiclistener.Listener.Accept routine which is mostly a black box apart from GetCertificate, so I made the change there to look at the client hello data and skip closing the connection that was in the middle of its handshake. |
bd2fd11 to
7fffacd
Compare
|
This unfortunately doesn't help if there are multiple requests made at once and the cert is updated for any of them, since all the connections are wrapped and then all except one are closed 🤔 |
|
Ah yeah, that doesn't help the other connections does it. Is there some way to add a flag to the wrapped connections to indicate whether or not we've finished the handshake (or at least returned a cert to be used for the handshake) yet? We only want to close connections that were completed before the cert was updated, right? |
7fffacd to
18f9020
Compare
|
Alright now the wrapper tracks whether the connection has ever gotten a cert and uses that to know whether it's safe to close |
18f9020 to
c84a3e1
Compare
Without this change, if a cert is updated (e.g. to add CNs) while the listener is in the middle of Accept()ing a new connection, the connection gets dropped, we'll see a message like this in the server logs: http: TLS handshake error from 127.0.0.1:51232: write tcp 127.0.7.1:8443->127.0.0.1:51232: use of closed network connection and the client (like a browser) won't necessarily reconnect. This change modifies the GetCertificate routine in the listener's tls.Config to keep track of the state of the incoming connections and only close connections that have completed GetCertificate and therefore are finished with their TLS handshake, so that only old established connections are closed.
c84a3e1 to
c7dd355
Compare
Without this change, if a cert is updated (e.g. to add CNs) while the
listener is in the middle of Accept()ing a new connection, the
connection gets dropped, we'll see a message like this in the server
logs:
http: TLS handshake error from 127.0.0.1:51232: write tcp 127.0.7.1:8443->127.0.0.1:51232: use of closed network connection
and the client (like a browser) won't necessarily reconnect. This change
modifies the GetCertificate routine in the listener's tls.Config to
keep track of the state of the incoming connections and only close
connections that have completed GetCertificate and therefore are
finished with their TLS handshake, so that only old established
connections are closed.
Issue: rancher/rancher#34038
Related context: