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

Usage Question / panic, tomb.go called after all goroutines terminated #9

Open
luck02 opened this issue Oct 31, 2015 · 0 comments
Open

Comments

@luck02
Copy link

luck02 commented Oct 31, 2015

Getting:

2015/10/30 23:10:40 http: panic serving [::1]:56269: tomb.Go called after all goroutines terminated

The use case may be not quite what you had envisioned.

I'm waiting on a usb/serial device and want to be able to cancel waiting (ctrl-c to kill the process hangs indefinitely right now because I can't close the port while I'm still waiting on an outstanding read that will never arrive).

so the flow is:

DoSomeProcessing()
...
func (msngr *Messenger) ReceiveAsync() (Message, error) {
    ch := make(chan recieveAsync)
    msngr.logger.Info.Println("Entering Tomb")
    msngr.tomb.Go(
        func() error {
            message, err := msngr.receive()
            messageRecieved := recieveAsync{Msg: message, Err: err}

            select {
            case ch <- messageRecieved:
                close(ch)
            case <-msngr.tomb.Dying():
                msngr.logger.Info.Println("Got dying from tomb")
                rec := recieveAsync{Msg: Message{}, Err: errors.New("Received Cancellation")}
                ch <- rec
                close(ch)
            }
            return nil
        })

    rec := <-ch
    msngr.logger.Info.Println("exiting tomb")
    return rec.Msg, rec.Err
}

So during execution the process should enter that, block on the rec:=<- ch multiple times, but also provide me the ability to kill it externall (on ctrl-c in this case).

At least that's the theory and it works the first time, my logs seem to indicate that the failure occurs after multiple reads, I don't see an overlap and an overlap shouldn't happen in normal process flow.

I'm pretty sure i'm missing something fundamental here, just not sure what it is. I'm also not returning a useful error at this point, I'm not sure how to approach that just yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant