ionorg / ion-sdk-go

ion sdk for golang
MIT License
55 stars 46 forks source link

panic: close of closed channel #34

Open manishiitg opened 3 years ago

manishiitg commented 3 years ago

Your environment.

What did you do?

https://github.com/pion/ion-sdk-go/blob/master/client.go#L241

if c.Close() is called before publish, it gives a panic

What did you expect?

What happened?

manishiitg commented 3 years ago

i think the issue is that when we do Close(), it interally calls delete and which again calls Close so it panics always

https://github.com/pion/ion-sdk-go/blob/master/client.go#L270

https://github.com/pion/ion-sdk-go/blob/1e8126477a4c28444a8b873d63aa6faf37078108/engine.go#L58

manishiitg commented 3 years ago

also client Close should internally Stop the webm producer as well, if its being used

brucekim commented 3 years ago

I suffer from the same issue.

Client.Close() calls Engine.DelClient() which calls Client.Close() again. This makes panic since it tries to close the closed channel, c.notify here.

Is there any reason that Engine.DelClient() does c.Close() again?

// DelClient delete a client
func (e *Engine) DelClient(c *Client) error {
    e.Lock()
    if e.clients[c.sid] == nil {
        e.Unlock()
        return errInvalidSessID
    }
/*
    if c, ok := e.clients[c.sid][c.uid]; ok && (c != nil) {
        c.Close()
    }
*/
    delete(e.clients[c.sid], c.uid)
    e.Unlock()
    return nil
}