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

feat: callback notify function when connection is refused #2308

Merged
merged 7 commits into from
Oct 23, 2024

Conversation

chechenglin
Copy link
Contributor

Add a command option for adding a callback function for the connection refuse events due to max connection limit.

@chechenglin chechenglin requested a review from a team as a code owner October 12, 2024 07:17
@jackwotherspoon
Copy link
Collaborator

@chechenglin I am trying to think if there is an easy way to test this new option...

cmd/options.go Outdated Show resolved Hide resolved
@jackwotherspoon
Copy link
Collaborator

@chechenglin I think we could probably update the TestClientLimitsMaxConnections with the new WithConnRefustNotifyoption:

func TestClientLimitsMaxConnections(t *testing.T) {

@chechenglin
Copy link
Contributor Author

@chechenglin I think we could probably update the TestClientLimitsMaxConnections with the new WithConnRefustNotifyoption:

func TestClientLimitsMaxConnections(t *testing.T) {

Good call. I just realized I did not update the caller in the tests. I'll need to update those callers. Will push a amend commit soon.

Che Lin added 2 commits October 22, 2024 20:42
@chechenglin
Copy link
Contributor Author

@chechenglin I think we could probably update the TestClientLimitsMaxConnections with the new WithConnRefustNotifyoption:

func TestClientLimitsMaxConnections(t *testing.T) {

Good call. I just realized I did not update the caller in the tests. I'll need to update those callers. Will push a amend commit soon.

Revised.

Copy link
Collaborator

@jackwotherspoon jackwotherspoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chechenglin! LGTM ✅

@enocom do you mind doing a review before we go ahead and merge this

cmd/options.go Outdated Show resolved Hide resolved
@jackwotherspoon
Copy link
Collaborator

Looks like TestClientLimitsMaxConnections is erroring on:

=== RUN   TestClientLimitsMaxConnections
2024/10/23 18:42:09 [proj:region:pg] Listening on 127.0.0.1:50011
2024/10/23 18:42:09 [proj:region:pg] Accepted connection from 127.0.0.1:54858
2024/10/23 18:42:09 [proj:region:pg] Accepted connection from 127.0.0.1:54844
2024/10/23 18:42:09 max connections (1) exceeded, refusing new connection
==================
WARNING: DATA RACE
Read at 0x00c000015eb8 by goroutine 71:
  github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/internal/proxy_test.TestClientLimitsMaxConnections()
      /home/runner/work/cloud-sql-proxy/cloud-sql-proxy/internal/proxy/proxy_test.go:418 +0x924
  testing.tRunner()
      /opt/hostedtoolcache/go/1.23.2/x64/src/testing/testing.go:1690 +0x226
  testing.(*T).Run.gowrap1()
      /opt/hostedtoolcache/go/1.23.2/x64/src/testing/testing.go:1743 +0x44

Previous write at 0x00c000015eb8 by goroutine 78:
  github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/internal/proxy_test.TestClientLimitsMaxConnections.func1()
      /home/runner/work/cloud-sql-proxy/cloud-sql-proxy/internal/proxy/proxy_test.go:375 +0x44

Goroutine 71 (running) created at:
  testing.(*T).Run()
      /opt/hostedtoolcache/go/1.23.2/x64/src/testing/testing.go:1743 +0x825
  testing.runTests.func1()
      /opt/hostedtoolcache/go/1.23.2/x64/src/testing/testing.go:2168 +0x85
  testing.tRunner()
      /opt/hostedtoolcache/go/1.23.2/x64/src/testing/testing.go:1690 +0x226
  testing.runTests()
      /opt/hostedtoolcache/go/1.23.2/x64/src/testing/testing.go:2166 +0x8be
  testing.(*M).Run()
      /opt/hostedtoolcache/go/1.23.2/x64/src/testing/testing.go:2034 +0xf17
  main.main()
      _testmain.go:99 +0x164

Goroutine 78 (finished) created at:
  github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/internal/proxy.(*Client).serveSocketMount.func1()
      /home/runner/work/cloud-sql-proxy/cloud-sql-proxy/internal/proxy/proxy.go:760 +0x455
==================
2024/10/23 18:42:09 [proj:region:pg] client closed the connection
    testing.go:1399: race detected during execution of test

@jackwotherspoon jackwotherspoon merged commit 9309b84 into GoogleCloudPlatform:main Oct 23, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants