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

server: move procCh init into Server.serveImpl #106943

Merged
merged 1 commit into from
Jul 21, 2023
Merged

server: move procCh init into Server.serveImpl #106943

merged 1 commit into from
Jul 21, 2023

Conversation

ecwall
Copy link
Contributor

@ecwall ecwall commented Jul 17, 2023

Informs #105448

This changes procCh to a sync.WaitGroup because the channel is never read
from and moves initialization into Server.serveImpl.

Also processCommandsAsync is changed to processCommands and the goroutine
is created inside Server.serverImpl to avoid needing a procCh parameter.

Release note: None

@ecwall ecwall requested review from a team as code owners July 17, 2023 20:21
@blathers-crl
Copy link

blathers-crl bot commented Jul 17, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@ecwall ecwall changed the title server: move procCh init and receive into Server.ServeConn server: move procCh init and close into Server.serveImpl Jul 17, 2023
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

nice, seems like a great simplification. left one suggestion

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ecwall)


pkg/sql/pgwire/server.go line 972 at r1 (raw file):

	// procCh is the channel on which we'll receive the termination signal from
	// the command processor.
	procCh := make(chan struct{})

nit: this could be a bounded channel of size 1

Copy link
Contributor Author

@ecwall ecwall left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)


pkg/sql/pgwire/server.go line 972 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

nit: this could be a bounded channel of size 1

The channel can be unbuffered because nothing is ever sent or received from it. It just blocks until it is closed like this example https://medium.com/@matryer/golang-advent-calendar-day-two-starting-and-stopping-things-with-a-signal-channel-f5048161018.

Is there some other reason to give it size 1?

@ecwall ecwall requested a review from rafiss July 20, 2023 20:59
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ecwall)


pkg/sql/pgwire/server.go line 972 at r1 (raw file):

Previously, ecwall (Evan Wall) wrote…

The channel can be unbuffered because nothing is ever sent or received from it. It just blocks until it is closed like this example https://medium.com/@matryer/golang-advent-calendar-day-two-starting-and-stopping-things-with-a-signal-channel-f5048161018.

Is there some other reason to give it size 1?

my thinking was just to prevent an accidental memory leak, in case someone does start sending to it.

another option is to use a WaitGroup. but i don't feel strongly about it - they just are less confusing to me than channels.

Informs #105448

This changes `procCh` to a `sync.WaitGroup` because the channel is never read
from and moves initialization into `Server.serveImpl`.

Also `processCommandsAsync` is changed to `processCommands` and the goroutine
is created inside `Server.serverImpl` to avoid needing a `procCh` parameter.

Release note: None
@ecwall ecwall changed the title server: move procCh init and close into Server.serveImpl server: move procCh init into Server.serveImpl Jul 21, 2023
Copy link
Contributor Author

@ecwall ecwall left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)


pkg/sql/pgwire/server.go line 972 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

my thinking was just to prevent an accidental memory leak, in case someone does start sending to it.

another option is to use a WaitGroup. but i don't feel strongly about it - they just are less confusing to me than channels.

Changed to sync.WaitGroup.

@ecwall
Copy link
Contributor Author

ecwall commented Jul 21, 2023

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Jul 21, 2023

Build succeeded:

@craig craig bot merged commit be21b3b into cockroachdb:master Jul 21, 2023
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.

3 participants