-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
bastion: Close backend connections on failure #20
base: main
Are you sure you want to change the base?
bastion: Close backend connections on failure #20
Conversation
go func() { | ||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) | ||
defer cancel() | ||
cc.Shutdown(ctx) | ||
}() |
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.
Duplicated from the handleBackend method below, could use some better abstraction.
What failure scenario does this address? In #11 we see a RoundTrip error at I think in that case the only difference this change would make is dropping the p.conns entry for the closed connection, turning whatever error a closed connection causes into a |
I don't quite remember my analysis when I came up with this change. But I think my theory was that the connection between bastion and backend (i.e., one of the witnesses) has somehow gotten into a bad state, then the RoudTrip call will return error. If at this point we throw out the backend, disconnecting the underlying tls connection, the witness is likely to reconnect and we will recover from the bad state. Is there ever a good reason to keep calling the RoundTrip method on a http2.ClientConn after that method have started failing? It's also unclear to my how the error from RoundtTrip is propagated after this code returns, is it sent over the wire to the client (i.e., the log), or written to the bastion's log file? |
That might be, but it's not consistent with the logs in #11, where the connection is already closed immediately.
RoundTrip can fail because the stream times out, or is aborted for any other reason, while the connection is still healthy. Remember that a HTTP/2 backend connection is shared by multiple clients (logs). If we close the whole connection just because e.g. a log sent a request that's too long and the backend aborted it, we are introducing a DoS.
It's written to the log file prefixed with |
Ah, I haven't thought about DoS attacks on the bastion or via the bastion (would be nice with some analysis in the bastion spec). I can think of some different and obvious flavors:
Not clear to me how each of these types of abuse will be handled by the bastion, which ones will reach the Roundtrip method of interest, and how that method might report failure (also depending also on the behavior of the connected backend). And I'm also not familiar with the details of http/2 multiplexing. I hope the new logging will provide some more info on what's going wrong. |
Two additional observations:
|
This change aims to close backend connections whenever its Roundtrip method fails.
Please have a look if it makes sense; I'm not familiar with the related http and http2 packages.