shotover / shotover-proxy

L7 data-layer proxy
https://docs.shotover.io
Apache License 2.0
83 stars 16 forks source link

Add Wrapper::close_client_connection #1722

Closed rukai closed 3 weeks ago

rukai commented 1 month ago

In order for shotover to properly recreate the behavior of certain databases it needs to be able to close incoming connections from the client. Databases will close the connection on the client if it misbehaves, this can include things like failed auth and sending requests that cannot be parsed according to the databases wire protocol. We need to be able to recreate this behavior to avoid subtle differences in behavior between shotover and the database.

Shotover currently lacks a way for a transform to close the incoming connection to the client. This is a problem since cluster sink transforms need to be able to close the connection since they need to emulate a chunk of the servers behavior.

This PR fills this missing hole in the API shotover exposes to transforms and makes use of this new API in KafkaSinkCluster in order to close the client connection when authentication fails.

This is achieved by adding a close_client_connection field to Wrapper. By default the field is false, but any transform can set it to true, allowing any transform to close the connection to the client.

Additionally we use the CloseReason enum to avoid flushing the chain when a transform requests the connection to be closed. Chain flushing is needed to ensure we flush all pending responses back to the client, since shotover will not be sending anymore responses to the client it does not make sense to flush the chain.

This enables use cases such as:

In this PR, we only use close_client_connection for KafkaSinkCluster auth, as this is all we need for the "handling of down kafka nodes" project.

codspeed-hq[bot] commented 1 month ago

CodSpeed Performance Report

Merging #1722 will not alter performance

Comparing rukai:shotover_close_connection_field (2bd030d) with main (17ccad5)

Summary

✅ 39 untouched benchmarks