Skip to content
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

Unix socket: add switch to disable adding the instance name to path #2302

Closed
eldad opened this issue Sep 27, 2024 · 4 comments
Closed

Unix socket: add switch to disable adding the instance name to path #2302

eldad opened this issue Sep 27, 2024 · 4 comments
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@eldad
Copy link

eldad commented Sep 27, 2024

Feature Description

When creating a unix socket (-u), the name of the instance is concatenated to the path given by -u. This can cause an issue even if -u is very short: when using a long instance name, creating a UNIX socket can fail due to the length restriction.
(See also #970)

This can be avoided if cloud-sql-proxy would allow the user to disable adding the instance name as an extra directory, which is done here:

address = UnixAddress(dir, inst.Name)

I was able to workaround my local issues by building a custom version with address = dir at that line.
It would be great if there would be a switch to control this.

If this is acceptable to you, I'll be happy to contribute a PR to implement this.

Sample code

No response

Alternatives Considered

No response

Additional Details

Related issue: #970

With this simple change I can work with very long instance names:
https://github.com/eldad/cloud-sql-proxy/commit/950bb2a8e0502bd73dc0963fb1c6ed9e9eb78281
(obviously this behavior would need to be feature-flag controlled)

@eldad eldad added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Sep 27, 2024
@hessjcg
Copy link
Collaborator

hessjcg commented Sep 27, 2024

Hi, you are going to want to use the unix-socket-path parameter. This allows you to override the default socket path with your own, absolute path to the socket.

From the docs:

When necessary, you may specify the full path to a Unix socket. Set the
unix-socket-path query parameter to the absolute path of the Unix socket for
the database instance. The parent directory of the unix-socket-path must
exist when the Proxy starts or else socket creation will fail. For Postgres
instances, the Proxy will ensure that the last path element is
'.s.PGSQL.5432' appending it if necessary. For example,

      ./cloud-sql-proxy \
        'my-project:us-central1:my-db-server?unix-socket-path=/path/to/socket'

@hessjcg hessjcg closed this as completed Sep 27, 2024
@eldad
Copy link
Author

eldad commented Oct 7, 2024

Thanks, I was not aware of this option!
It would be great if it would be at mentioned in the --help text.

@jackwotherspoon
Copy link
Collaborator

It would be great if it would be at mentioned in the --help text

@eldad It is mentioned in the --help text, albeit somewhat hidden in the text.

cloud-sql-proxy/cmd/root.go

Lines 160 to 169 in c683042

When necessary, you may specify the full path to a Unix socket. Set the
unix-socket-path query parameter to the absolute path of the Unix socket for
the database instance. The parent directory of the unix-socket-path must
exist when the Proxy starts or else socket creation will fail. For Postgres
instances, the Proxy will ensure that the last path element is
'.s.PGSQL.5432' appending it if necessary. For example,
./cloud-sql-proxy \
'my-project:us-central1:my-db-server?unix-socket-path=/path/to/socket'

@eldad
Copy link
Author

eldad commented Oct 7, 2024

Hidden in plain sight 😄 My bad, I didn't even notice the whole text before the command line switches. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants