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

Problem when closing over variables in certain case, causes SIGSEGV: segmentation violation #481

Closed
gopherbot opened this issue Jan 1, 2010 · 5 comments

Comments

@gopherbot
Copy link
Contributor

by thevulgarprogrammer:

The smallest bit of code I could create to reproduce the problem with my output is here:

https://gist.github.com/e1c8c3f80050f6f4e76b

export GOOS=darwin
export GOARCH=amd64

Revision: 5074575b745b tip

I am still new to the language, but it appears that this is a problem with a closure in
this specific 
case. I tried to reproduce the crash in a case where I was not using the net package but
was 
unsuccessful.
@gopherbot
Copy link
Contributor Author

Comment 1 by jessta:

I notice that you're ignoring the returned error values from 
net.Listen()
listen.Accept()
net.Dial()
it's possible you're getting a nil back from these functions due to an error and then 
attempting to access that nil causing the seg fault.

@gopherbot
Copy link
Contributor Author

Comment 2 by thevulgarprogrammer:

I'm skipping the error checks in the snippet i showed to make it shorter, but that is
not the issue. You can check a longer version of the code here:
https://gist.github.com/e1c8c3f80050f6f4e76b/0481df04c2438cdce2108aaa84d813b817b7c3ba
where I do check the error values.
Also, if you remove line #9 ( go func() {) and the corresponding closing curly
bracket, everything works fine. This leads me to believe that there is some kind of
problem with the closure not retaining the "listen" variable.

@rsc
Copy link
Contributor

rsc commented Jan 3, 2010

Comment 3:

This is a compiler bug.  You can work around the
bug by using
   listen, _ := ...
instead of
   var listen, _ = ...

Labels changed: added compilerbug.

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

Status changed to Accepted.

@gopherbot
Copy link
Contributor Author

Comment 4 by thevulgarprogrammer:

I guess I found it since I prefer the var listen, err = ... syntax over listen, err :=
... syntax.

@rsc
Copy link
Contributor

rsc commented Jan 19, 2010

Comment 5:

This issue was closed by revision e0059ae.

Status changed to Fixed.

Merged into issue #-.

@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