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

runtime: go1.3 windows/amd64:system handle leaks in multithread c-callback #8517

Closed
gopherbot opened this issue Aug 12, 2014 · 12 comments
Closed
Milestone

Comments

@gopherbot
Copy link
Contributor

by policehsh:

run attachments,you can see each time we call test_handle_leaks_callback , a system
handle is leaked(you can Watch handles in windows task manager)

Attachments:

  1. main.go (286 bytes)
  2. test.c (321 bytes)
  3. test.h (93 bytes)
@dvyukov
Copy link
Member

dvyukov commented Aug 12, 2014

Comment 1:

Labels changed: added release-go1.4, repo-main.

Status changed to Accepted.

@dvyukov
Copy link
Member

dvyukov commented Aug 12, 2014

Comment 2:

Alex, I think the issue is here:
// Called to initialize a new m (including the bootstrap m).
// Called on the new thread, can not allocate memory.
void
runtime·minit(void)
{
    void *thandle;
    // -1 = current process, -2 = current thread
    runtime·stdcall(runtime·DuplicateHandle, 7,
        (uintptr)-1, (uintptr)-2, (uintptr)-1, &thandle,
        (uintptr)0, (uintptr)0, (uintptr)DUPLICATE_SAME_ACCESS);
    runtime·atomicstorep(&g->m->thread, thandle);
}
// Called from dropm to undo the effect of an minit.
void
runtime·unminit(void)
{
}
We leak the thread handle during each C->Go callback on external thread.
We need to close the handle. We can't keep it for later as, I think, extram's are reused
across different threads.

@dvyukov
Copy link
Member

dvyukov commented Aug 12, 2014

Comment 3:

We also need to close per M sema used in lock_sema.c and maybe some other per-thread
handles.

@dvyukov
Copy link
Member

dvyukov commented Aug 12, 2014

Comment 4:

OK, the sema can stay there, it will be reused for future callbacks along with the
extram.

@ianlancetaylor
Copy link
Member

Comment 5:

Labels changed: added os-windows.

@alexbrainman
Copy link
Member

Comment 6:

I will try to fix this, but I am busy now. A test would be nice, but ...
Calling Go from C on non-Go thread does not work. See issue #6751. I think we should fix
both issues. I tried to fix issue #6751 (see diff in
https://golang.org/issue/6751?c=3). but that triggers "all
goroutines are asleep - deadlock!" panic. I could not work out what needs to be adjusted
in checkdead.
Alex

@alexbrainman
Copy link
Member

Comment 7:

Dmitriy, linux and windows race builders are off dashboard.
Alex

@dvyukov
Copy link
Member

dvyukov commented Aug 13, 2014

Comment 8:

issue #6751 is about syscall.NewCallback, this issue is about cgo callbacks.

@gopherbot
Copy link
Contributor Author

Comment 9:

CL https://golang.org/cl/145890044 mentions this issue.

@rsc
Copy link
Contributor

rsc commented Sep 19, 2014

Comment 10:

This issue was closed by revision 88d53dd.

Status changed to Fixed.

@gopherbot
Copy link
Contributor Author

Comment 11:

CL https://golang.org/cl/148790043 mentions this issue.

@alexbrainman
Copy link
Member

Comment 12:

This issue was updated by revision 9ca8368.

LGTM=rsc
R=golang-codereviews, rsc
CC=golang-codereviews
https://golang.org/cl/148790043

@rsc rsc added this to the Go1.4 milestone Apr 14, 2015
@rsc rsc removed the release-go1.4 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018
Fixes golang#8517.

LGTM=dvyukov, alex.brainman
R=golang-codereviews, dvyukov, alex.brainman
CC=golang-codereviews
https://golang.org/cl/145890044
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018
Fixes golang#8517.

LGTM=dvyukov, alex.brainman
R=golang-codereviews, dvyukov, alex.brainman
CC=golang-codereviews
https://golang.org/cl/145890044
wheatman pushed a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018
Fixes golang#8517.

LGTM=dvyukov, alex.brainman
R=golang-codereviews, dvyukov, alex.brainman
CC=golang-codereviews
https://golang.org/cl/145890044
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

5 participants