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

time: zero value of time.Timer crashes confusingly #8776

Closed
gopherbot opened this issue Sep 19, 2014 · 4 comments

Comments

Projects
None yet
4 participants
@gopherbot
Copy link

commented Sep 19, 2014

by gima@iki.fi:

What does 'go version' print?
go version go1.3.1 linux/amd64

Additional info:
hg branch: default
changeset: 21052:5cd7f2bfb5f6
tag: tip


What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.
    1. `go run` the attached "test.go" file.

    (The code is also available at https://play.golang.org/p/earSjQISp8
     Please note that while the link is to the playground, the code is
     NOT supposed to run there. I could have used Pastebin, but I though 
     playground to be more future-proof way to share the code.) 



What happened?
    fatal error: unexpected signal during runtime execution
    [signal 0xb code=0x1 addr=0x0 pc=0x422f87]

    goroutine 20 [running]:
    runtime.throw(0x48f865)
            /usr/lib/go/src/pkg/runtime/panic.c:520 +0x69 fp=0x7f166080bf40 sp=0x7f166080bf28
    runtime.sigpanic()
            /usr/lib/go/src/pkg/runtime/os_linux.c:222 +0x3d fp=0x7f166080bf58 sp=0x7f166080bf40
    timerproc()
            /usr/lib/go/src/pkg/runtime/time.goc:232 +0x157 fp=0x7f166080bfa8 sp=0x7f166080bf58
    runtime.goexit()
            /usr/lib/go/src/pkg/runtime/proc.c:1445 fp=0x7f166080bfb0 sp=0x7f166080bfa8
    created by addtimer
            /usr/lib/go/src/pkg/runtime/time.goc:113

    goroutine 16 [runnable]:
    main.main()
            /home/gima/goworkspace/src/random.proj/test.go:17 +0xb2
    exit status 2


What should have happened instead?
    The program should have run and exited without any errors or output.


Please provide any additional information below.
    The fatal error does not occur if the channels are not used (read and 
    written) like they are in the provided demonstration code, so this is 
    probably not just a problem with the Timer implementation struct, but 
    something deeper. 

    The correct behavior should be, in my opinion, to provide a meaninful 
    panic, if the usage of zero-valued `Timer{}` struct is not valid. 

    Also currently, the `time.Timer` has no way of initializing a `Timer` 
    struct without starting it, which I was trying to do when I ran into 
    this bug. So a welcome addition would be to enable usage of zero-valued 
    `Timer{}` struct (so `.Reset` can be called on it).

Attachments:

  1. test.go (214 bytes)
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Sep 19, 2014

Comment 1:

I don't see why this program should run without any errors.  You can't use time.Timer
without creating it via NewTimer or a similar function.  I agree that the crash is not
very useful, and perhaps the documentation could be better.

Labels changed: added repo-main, release-none.

Status changed to Accepted.

@bradfitz

This comment has been minimized.

Copy link
Member

commented Sep 19, 2014

Comment 2:

Related (almost a dup but not quite): issue #8721 about Reset of zero Timer on the
playground, where it doesn't crash. The behavior there should be the same.
@griesemer

This comment has been minimized.

Copy link
Contributor

commented Oct 1, 2014

Comment 3:

I agree with iant. A time.Timer must be created properly. Documented accordingly:
https://golang.org/cl/145710043
The likely reason why it's not crashing in the playground is that the playground's
runtime code is older (and different) from the one at tip.
@griesemer

This comment has been minimized.

Copy link
Contributor

commented Oct 1, 2014

Comment 4:

This issue was closed by revision bc89e8c.

Status changed to Fixed.

@gopherbot gopherbot added fixed labels Oct 1, 2014

@golang golang locked and limited conversation to collaborators Jun 25, 2016

wheatman added a commit to wheatman/go-akaros that referenced this issue Jun 25, 2018

wheatman added a commit to wheatman/go-akaros that referenced this issue Jun 26, 2018

wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 9, 2018

wheatman added a commit to wheatman/go-akaros that referenced this issue Jul 30, 2018

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.