Skip to content

Accept loop has improper error handling, causing wrong exit code. #2372

Description

@hessjcg

When the proxy receives a SIGTERM, it will close this server socket. This can result in the server.Accept() returning a non-nil error with the message
"proxy server error: accept tcp" or "use of closed network connection". This error will be put into the error channel, causing the process end with exit code 2, instead of the appropriate 143 (TERMINATED) or 0 (SUCCESS).

See https://github.com/GoogleCloudPlatform/cloud-sql-proxy/blob/main/cmd/root.go#L1143

Activity

  1. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Jan 21, 2025
  2. changed the title [-]This may result in an exit code error status[/-] [+]Accept loop has improper error handling, causing wrong exit code.[/+] on Jan 21, 2025
  3. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Jan 21, 2025
  4. hessjcg commented on Apr 22, 2025

    @hessjcg
    MemberAuthor

    Still looking into this one.

  5. hessjcg commented on Aug 12, 2025

    @hessjcg
    MemberAuthor

    Keeping this on the backlog for now. We would like to resolve it.

  6. eremeevfd commented on Sep 19, 2025

    @eremeevfd

    @hessjcg thanks for opening the issue! we faced the same thing recently, did you find any workaround for now?

  7. eremeevfd commented on Sep 19, 2025

    @eremeevfd

    okay sorry, I found an answer myself

    My context is this: I'm using kubernetes and use cloud-sql-proxy in CronJobs, recently I've migrated just hosting a proxy in a container to a native sidecar (init container) and got a lot of errors, I thought it was related to the original reported error for SIGTERM, however I've missed that the proxy returns code 143 instead of 0 on SIGTERM, so I just needed to add a flag

    --exit-zero-on-sigterm

    to make it work properly

  8. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    priority: p3Desirable enhancement or fix. May not be included in next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    and removed
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Sep 23, 2025
  9. hessjcg commented on Sep 23, 2025

    @hessjcg
    MemberAuthor

    This is still a valid issue, but I'm moving it to a P3 for now since --exit-zero-on-sigterm works correctly under most circumstances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions