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

goroutines blocked on channel send are not collected #296

Closed
gopherbot opened this issue Nov 22, 2009 · 6 comments
Closed

goroutines blocked on channel send are not collected #296

gopherbot opened this issue Nov 22, 2009 · 6 comments

Comments

@gopherbot
Copy link

by suraci.alex:

Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
This is kind of specific, but I'm reporting from a live use scenario; I'll 
work on a small testcase soon, but right now it's late.

1. Handle http requests with something that stores callback functions for 
matched URLs in a vector (e.g. a controller).
2. In the handling function, loop over the vector with route := range 
(foo).Iter();
3. Run ab over it and watch the memory usage rise steadily, rather quickly.

What is the expected output? What do you see instead?
Slight memory increase that drops back to normal once the benchmark is 
over. Instead, memory usage rose a steady 2% per second (out of 6 gigs) 
eventually gobbling it all up and leaving me holding ctrl-C as my music 
skips.


What is your $GOOS?  $GOARCH?
src $ env | grep GO
GOBIN=/home/alex/bin
GOARCH=amd64
GOROOT=/home/alex/go
GOOS=linux


Which revision are you using?  (hg identify)
src $ hg identify
2f32e74ab96e tip

Please provide any additional information below.
http://gopaste.org/view/QM696 - Abridged, with an example of what doesn't 
leak.
http://gopaste.org/view/ChRC8#LC42 - Full source. (Relevant line deep-
linked; #42)
@rsc
Copy link
Contributor

rsc commented Nov 25, 2009

Comment 1:

The issue is that if your code breaks out of the for loop
at line 83, then the goroutine created by the .Iter() is
still trying to send to the channel that you're ranging
over, but you've stopped reading it.  The workaround
for now is to use .Data() instead of .Iter()

Owner changed to r...@golang.org.

Status changed to LongTerm.

@rsc
Copy link
Contributor

rsc commented Dec 2, 2009

Comment 2:

Labels changed: added languagechange.

@gopherbot
Copy link
Author

Comment 3 by Ziyu4Huang:

I think it's really a serous problem for my short example here:
package main
import "container/vector"
func main() {
  var v vector.Vector;
  for i:=0; i < 100; i++{
    v.Push(i);
  }
  for i:=0; i< 1000000; i++ {
    j:=0;
    for v:= range v.Iter() {
      if j > 3 { break}
      j++;
      _ = v;
    }
  }
}
If you don't fix earlier, I can image how much trouble it may cause.
It's very open that code may break before Iter() complete, if there is no way to 
automatically close, I suggest don't use it as iterator idiom.

@rsc
Copy link
Contributor

rsc commented Dec 13, 2009

Comment 4:

For your specific example, you should be ranging over
v.Data() anyway.  We don't have any data structures
yet that require the use of Iter. 
Whether channel iterator access turns out to be a
good idea for arbitrary data structures is yet to
be determined.  It obviously needs some work, but
it's not a top priority right now (garbage collector,
maybe generics, maybe exceptions, ...).
However, using channels for iteration isn't the only
reason to have range on channels.  The examples like
the prime sieve (or, a real example, the rpc package)
make good use of range over channels.

@rsc
Copy link
Contributor

rsc commented Sep 15, 2010

Comment 5:

Issue #1111 has been merged into this issue.

@rsc
Copy link
Contributor

rsc commented Apr 20, 2011

Comment 6:

I think goroutines are not going to be magically collected.

Status changed to WontFix.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants