-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Audit all commands for goroutine leaks #4414
Comments
@Stebalien Regarding your question in #4413:
When we cancel, the error should either be correctly handled or the command should return an error indicating the command was cancelled. Maybe even specify select {
case <-ctx.Done():
res.SetError(ctx.Err(), cmdkit.ErrNormal)
case default:
} at the end of the respective commands. Does that sound reasonable to you? |
It's reasonable, just verbose and painful; in some cases, we realize that the context has been canceled in multiple places concurrently (thread safety issues). If the context has been canceled/expired, I assume the client isn't waiting for a response anyways. If they are, can the commands package not handle this? |
Note: We should not be closing the channel on context cancel. Otherwise, the other side might think that we're done sending the response. We need to fix the PR #4413. |
…imed out). Previously, the following could happen: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and closes the channel. - Consumer sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and DOES NOT close the channel. - Consumer sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414.
…imed out). Previously, the following could happen: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and closes the channel. - Consumer sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and DOES NOT close the channel. - Consumer sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414.
…imed out). Previously, the following could happen: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and closes the channel. - Consumer sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and DOES NOT close the channel. - Consumer sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414. License: MIT Signed-off-by: Lucas Garron <[email protected]>
…imed out). Previously, the following could happen: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and closes the channel. - Consumer sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and DOES NOT close the channel. - Consumer sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414. License: MIT Signed-off-by: Lucas Garron <[email protected]>
…imed out). Previously, the following could happen: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and closes the channel. - Consumer sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and DOES NOT close the channel. - Consumer sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414. License: MIT Signed-off-by: Lucas Garron <[email protected]>
…imed out). Previously, the following could happen: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and closes the channel. - Consumer sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and DOES NOT close the channel. - Consumer sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414. License: MIT Signed-off-by: Lucas Garron <[email protected]>
…imed out). Previously, the following could happen: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and closes the channel. - Consumer sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Producer creates channel. - Consumer reads from channel. - Producer observes that the context has errored, and DOES NOT close the channel. - Consumer sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414. License: MIT Signed-off-by: Lucas Garron <[email protected]>
…imed out). Previously, the following could happen: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and closes the channel. - Receiver sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and DOES NOT close the channel. - Receiver sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414. License: MIT Signed-off-by: Lucas Garron <[email protected]>
…imed out). Previously, the following could happen: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and closes the channel. - Receiver sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and DOES NOT close the channel. - Receiver sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414. License: MIT Signed-off-by: Lucas Garron <[email protected]>
…imed out). Previously, the following could happen: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and closes the channel. - Receiver sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and DOES NOT close the channel. - Receiver sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414. License: MIT Signed-off-by: Lucas Garron <[email protected]>
…imed out). Previously, the following could happen: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and closes the channel. - Receiver sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and DOES NOT close the channel. - Receiver sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414. License: MIT Signed-off-by: Lucas Garron <[email protected]>
…imed out). Previously, the following could happen: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and closes the channel. - Receiver sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and DOES NOT close the channel. - Receiver sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414. License: MIT Signed-off-by: Lucas Garron <[email protected]>
…imed out). Previously, the following could happen: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and closes the channel. - Receiver sees the closed channel before seeing the context error, and assumes that command completed without a context error. This change ensures the following: - Sender creates channel. - Receiver reads from channel. - Sender observes that the context has errored, and DOES NOT close the channel. - Receiver sees that the context has errored, and handles the channel appropriately. Note that per the definition of context [1], a context is "done" iff it has not "errored" (i.e. ctx.Err() is non-nil). [1] https://godoc.org/context#Context Updates call sites touched by ipfs#4413 and addresses ipfs#4414. License: MIT Signed-off-by: Lucas Garron <[email protected]>
Hi, all! Is this issue still active? I'd like to get involved with some entry-level work on the project to get my hands dirty and this issue seemed like it still needed some work done. |
@forstmeier I'm interested in getting into IPFS as well, and I'm also interested in working on this issue. It doesn't seem super active, but if you're interested, we might be able to jointly look into this. Some of the files seem clean, but I'm not super experienced at Go, and I'm not great at intuitively knowing when a goroutine might hang. |
Hey, @alecbrick, I saw that you've submitted fixes for dag.go and pin.go - do you want me to look through refs.go? Also, I agree that some of these files listed in the issue appear to be clean (as far as I can tell). |
Description: This addresses one of the listed problem files in #4414. I chose to keep the return statement outside of the select statement on line 132 since that behavior was already there following the write to out. License: MIT Signed-off-by: John Forstmeier <[email protected]>
@Stebalien there are one goroutine leaks in filestore.go.So please help me review pr #5427 ,Thx a lot |
Hi @Stebalien,
the code in those file is the same.
so please tell me if you need more help in this issue or any other, I am looking for contribute with you. |
The I wouldn't bother deduplicating them either. Instead, we should focus on switching to the new Commands API that doesn't need that helper (you'll notice that some commands don't use That last |
Hi @Stebalien,
|
It looks like there are some cases in core/commands/pin.go and one in core/commands/refs.go (WriteEdge "checks" the context but the check is racy). |
This was fixed. |
We're leaking goroutines on canceled commands all over the place.
To do this audit, I recommend looking at all channel writes and I mean all.
A quick grep indicates that the following files may have issues (should, at least, be looked at):
core/commands/dht.go
-- Fix some goroutine leaks in commands #4413core/commands/repo.go
-- Fix some goroutine leaks in commands #4413core/commands/add.go
core/commands/dag/dag.go
core/commands/files/files.go
core/commands/commands.go
core/commands/filestore.go
core/commands/object/object.go
core/commands/pin.go
core/commands/ping.go
core/commands/unixfs/unixfs.go
core/commands/refs.go
Basically, anytime we write to a channel that may block (i.e., doesn't have a buffer at least as large what we're writing), we should select on the channel write and
<-req.Context().Done()
.The text was updated successfully, but these errors were encountered: