gatewayd-io / gatewayd

☁️ Cloud-native database gateway and framework for building data-driven applications ✨ Like API gateways, for databases ✨
https://gatewayd.io
GNU Affero General Public License v3.0
218 stars 17 forks source link

Fix Consistent Hashing to Use Remote Address Instead of Local Address #599

Closed sinadarbouy closed 4 weeks ago

sinadarbouy commented 1 month ago

Description

This PR updates the consistent hashing logic to use the remote address (RemoteAddr) of a connection instead of the local address (LocalAddr). The change addresses the following issues:

  1. When a new connection is opened, LocalAddr points to the gateway address, while RemoteAddr correctly points to the client’s source IP. The previous use of LocalAddr caused issues, such as always directing traffic to the same database.
  2. The fallback behavior now utilizes the full remote address (IP:port) as the key when useSourceIP is set to false. This change fixes the issue where the useSourceIP is disabled, as the remote address has a random port each time, making the key different.

Additionally, this PR:

Development Checklist

Legal Checklist