cloud-sql-go-connector
cloud-sql-go-connector copied to clipboard
Improve error messages surrounding `serverProxyPort` port 3307
Feature Description
It is confusing that it uses port 3307 as serverProxyPort
, because it resembles the MySQL port number and is some times used for the local mysql port (if 3306 is unavailable).
https://github.com/GoogleCloudPlatform/cloud-sql-proxy/issues/1841#issuecomment-1592714552
So maybe the server side proxy component should be using a port number that does not resemble any of the ports normally used by the databases (are the proxy components using ssh, then maybe just 22 or a port number resembling ssh, for instance 2222).
https://github.com/GoogleCloudPlatform/cloud-sql-go-connector/blob/68a58cdf4c2f390e45ba09daf0e339fc15b9756d/dialer.go#L47 https://github.com/GoogleCloudPlatform/cloud-sql-go-connector/blob/f1bcda8170c7318d29de958a42ee457e8b0193b5/internal/mock/cloudsql.go#L302
Sample code
serverProxyPort = "2222"
ln, err := tls.Listen("tcp", ":2222", &tls.Config{
This would also require a change in the server code. It would probably require the connector to try to first connect to 2222 and then fall back to 3307, in case the server has not been launched with the new port yet. The server code would probably listen to both ports, while updating all the connectors.
Alternatives Considered
This could also instead be remedied by a better error message when the connector cannot connect to the server.
Additional Details
No response
Hi @runephilosof-karnovgroup!
Thanks for the feature request on the Cloud SQL Go Connector 😄
It is confusing that it uses port 3307 as serverProxyPort, because it resembles the MySQL port number and is some times used for the local mysql port (if 3306 is unavailable).
I understand that the port number being 3307
may cause some slight confusion with the similarity to MySQL default port. The reason for the proxy server port initially being 3307
was for the intention of having it actually be similar to that of the MySQL port. This was because when the Cloud SQL Proxy first launched, Cloud SQL at the time only supported MySQL databases. This obviously didn't scale perfectly and as you mentioned maybe causes a bit of confusion for Postgres or SQL Server users.
This would also require a change in the server code. It would probably require the connector to try to first connect to 2222 and then fall back to 3307, in case the server has not been launched with the new port yet.
Not only would this require a backend change to the proxy server and to the Cloud SQL Go Connector, it would also require changes to the other Cloud SQL Language Connectors (Python, Node, Java). On top of this we have been using 3307
as the server proxy port for years so we have to take into account that most of our customers are familiar with this and changing it purely for convenience may cause more headaches than the convenience it provides.
I will discuss this over with the team but I think a more likely solution is to provide more detailed error messages to aid in resolving errors relating to the proxy server port and to update our docs https://github.com/GoogleCloudPlatform/cloud-sql-proxy/issues/1841 for the Connectors and Proxy to be more clear about the server proxy port.
Thanks again for the feature request and providing valuable insights. Let us know if there are any other pain points you found with the Cloud SQL Proxy or Go Connector and we can see what we can do 😄
@runephilosof-karnovgroup Can you elaborate on the problem you're trying to solve? The proxy server port should mostly be an invisible implementation detail. The only place it matters is where people want to lock down their firewall and would need to allow this port.
If connection fails you will see this error message
Listening on 127.0.0.1:5432
accepted connection from 127.0.0.1:58436
failed to connect to instance: Dial error: failed to dial (connection name = "xxx"): dial tcp x.x.x.x:3307: i/o timeout
Which can be quite confusing, because that implementation detail is so invisible, that it is not obvious what is causing the problem, especially if you start thinking 3307 has something to do with MySQL, when you are trying to use it for PostgreSQL.
Hi @runephilosof-karnovgroup! I have updated this bug to track improving the error messages surrounding the server proxy port. Hopefully more detailed error messages will help resolve the confusion, if they do not we can take another look at the port number itself. 😄