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

Guaranty completion of signals handling #4347

Closed
gopherbot opened this issue Nov 5, 2012 · 7 comments
Closed

Guaranty completion of signals handling #4347

gopherbot opened this issue Nov 5, 2012 · 7 comments
Milestone

Comments

@gopherbot
Copy link

by jose.espinosa@moovweb.com:

go version: go1.0.3

I am writing a server and need to intercept the Interrupt signal in order to do some
clean up.  It works fine on Mac and Linux but the executing of the clean up code never
finish on Windows.  Look at code at http://play.golang.org/p/Nw0Bkb8hpj for a snippet 

What steps will reproduce the problem?
1. Download, compile and run the code at http://play.golang.org/p/Nw0Bkb8hpj
2. Press Ctrl-C

What is the expected output?

The server needs to finish the signal handling, this shall be the output.

Jose:server jose$ go build && ./server
Starting server
Registering signals
^CGetting signal  interrupt
Finishing clean up quiting
Jose:server jose$ 

What do you see instead?

The handling of the signal does not finish and this is printed (every time)

Jose:server jose$ go build && ./server
Starting server
Registering signals
Getting signal  interrupt

Jose:server jose$ 

Which compiler are you using (5g, 6g, 8g, gccgo)?
gcc 4.6.2 installed from MINGW

Which operating system are you using?
Windows 7

Which version are you using?  (run 'go version')
go1.0.3

Please provide any additional information below.
@alexbrainman
Copy link
Member

Comment 1:

That is what I see here:
C:\>test.exe
Starting server
Registering signals
Getting signal  interrupt
Finishing clean up quiting
C:\>
windows 7 
goos/goarch = windows/amd64
hg id = a9b2f3280559
So, there is no problem here. Please, give me more help to reproduce your problem. Thank
you.
Alex
PS: syscall.SIGINT has different name os.Interrupt. syscall package is os specific, you
should not use it in program that runs on many oses.

Status changed to WaitingForReply.

@gopherbot
Copy link
Author

Comment 2 by jose.espinosa@moovweb.com:

Hey Alex,
Thanks for taking a look at this.
I compile go on the id a9b2f3280559 and still find the problem.
I dig a little bit further and I think you will be able to reproduce it if you increase
the sleep time.  Please change line 25 to "time.Sleep(50 * time.Second)" 
A arbitrary large delay is the heart of the issue.  The handling of the signal does it
is not warranty to finish thus we can't warranty that the server will clean up when
exiting.

@alexbrainman
Copy link
Member

Comment 3:

I tried with different timeouts (7, 22, 50 and 150) on both XP and Windows 7 and it runs
just fine:
c:\MinGW64\go\src>\\sob\pub\test
Starting server
Registering signals
Getting signal  interrupt
Finishing clean up quiting
c:\MinGW64\go\src>
Does it work properly for you for any Sleep values? Perhaps you could run it in debugger
or something to see what happens to the process when it "dies"?
Alex

@gopherbot
Copy link
Author

Comment 4 by jose.espinosa@moovweb.com:

Alex,
I found the difference on our environments.  I am running it in the MinGW shell.  I try
the test case on the "cmd" shell and it works as intended.
Will dig further and post any new finding.
Alex, thanks for your help.
Jose

@alexbrainman
Copy link
Member

Comment 5:

We just add another "signal handler" to existing list of console handlers -
SetConsoleCtrlHandler
(http://msdn.microsoft.com/en-us/library/windows/desktop/ms686016%28v=vs.85%29.aspx).
Perhaps mingw console process installs its own handlers into every process it runs.
Perhaps, these are inherited somehow.
I still do not discount the possibility of bug in Go. The handler is run in its own
thread. There might be some problems there.
Alex

@gopherbot
Copy link
Author

Comment 6 by jose.espinosa@moovweb.com:

I was able to reproduce the issue on a pure C program on the MinGW shell.
And I found this issue
http://sourceforge.net/tracker/index.php?func=detail&aid=1333217&group_id=2435&atid=102435
saying that CYGWIN does not forward the signals properly.

@alexbrainman
Copy link
Member

Comment 7:

Status changed to Retracted.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
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

3 participants