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

Close channels inside a Once and don't set channels to nil #249

Open
Zerpet opened this issue Oct 26, 2023 · 0 comments
Open

Close channels inside a Once and don't set channels to nil #249

Zerpet opened this issue Oct 26, 2023 · 0 comments
Labels
v2.x Applicable to v2.x issues
Milestone

Comments

@Zerpet
Copy link
Contributor

Zerpet commented Oct 26, 2023

if tc.confirmsCh != nil {
close(tc.confirmsCh)
tc.confirmsCh = nil
}
if tc.chunkCh != nil {
close(tc.chunkCh)
tc.chunkCh = nil
}
if tc.socketClosedCh != nil {
close(tc.socketClosedCh)
tc.socketClosedCh = nil
}

Setting the channel to nil comes at a risk of blocking infinitely if any receiver attempts to receive.

Receiving from a nil channel blocks forever.

https://go.dev/ref/spec#Receive_operator

It probably does not block inside the smart layer, but this is an unnecesary risk, when there's another option available to achieve idempotent shutdown()

@Zerpet Zerpet added the v2.x Applicable to v2.x issues label Oct 26, 2023
@Zerpet Zerpet added this to the 2.0 milestone Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2.x Applicable to v2.x issues
Projects
None yet
Development

No branches or pull requests

1 participant