Merge pull request #6 from rubyist/master
Unexpected client disconnections can cause a panic and crash the server
This commit is contained in:
commit
bb439ce0e5
7
grace.go
7
grace.go
@ -60,10 +60,11 @@ type deadliner interface {
|
|||||||
type conn struct {
|
type conn struct {
|
||||||
net.Conn
|
net.Conn
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
|
once sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c conn) Close() error {
|
func (c *conn) Close() error {
|
||||||
defer c.wg.Done()
|
defer c.once.Do(c.wg.Done)
|
||||||
return c.Conn.Close()
|
return c.Conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +134,7 @@ func (l *listener) Accept() (net.Conn, error) {
|
|||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return conn{Conn: c, wg: &l.wg}, nil
|
return &conn{Conn: c, wg: &l.wg}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type Process struct {
|
type Process struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user