Skip to content

Commit

Permalink
Fix some really stupid bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
pdf committed Aug 6, 2016
1 parent 0ddfa26 commit ab25224
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
5 changes: 0 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,6 @@ func (c *Client) subscribe() error {
events := sub.Events()

go func() {
defer func() {
if err = sub.Close(); err != nil {
common.Log.Warnf("Failed closing protocol subscription: %v", err)
}
}()
for {
select {
case <-c.quitChan:
Expand Down
2 changes: 1 addition & 1 deletion protocol/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (p *V2) Close() error {
return common.ErrClosed
default:
close(p.quitChan)
p.wg.Done()
p.wg.Wait()
close(p.deviceQueue)
}

Expand Down
16 changes: 8 additions & 8 deletions protocol/v2/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,6 @@ func (d *Device) Close() error {
}
}

d.Lock()
defer d.Unlock()

select {
case <-d.quitChan:
common.Log.Warnf(`device already closed`)
Expand All @@ -712,10 +709,14 @@ func (d *Device) Close() error {
close(d.quitChan)
d.Lock()
for seq, res := range d.responseMap {
res.ch <- packet.Response{Error: common.ErrClosed}
select {
case res.ch <- packet.Response{Error: common.ErrClosed}:
case <-res.done:
default:
close(res.done)
}
res.wg.Wait()
close(res.ch)
close(res.done)
delete(d.responseMap, seq)
}
d.Unlock()
Expand Down Expand Up @@ -751,11 +752,10 @@ func (d *Device) handler() {
res.wg.Add(1)
select {
case res.ch <- pktResponse:
res.wg.Done()
case <-res.done:
res.wg.Done()
d.delSeq(seq)
}
res.wg.Done()
}
}
}
Expand Down Expand Up @@ -790,8 +790,8 @@ func (d *Device) delSeq(seq uint8) {
if !ok {
return
}
d.Lock()
res.wg.Wait()
d.Lock()
close(res.ch)
delete(d.responseMap, seq)
d.Unlock()
Expand Down

0 comments on commit ab25224

Please sign in to comment.