Skip to content

Commit

Permalink
network: Close connection if recv queue is full
Browse files Browse the repository at this point in the history
  • Loading branch information
losfair committed Jul 9, 2018
1 parent af56729 commit 5f668fc
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func (n *Network) Accept(conn net.Conn) {
}
}()

checkRecvWindow := func() {
checkRecvWindow := func() error {
ready := make([]*protobuf.Message, 0)

recvMutex.Lock()
Expand All @@ -402,16 +402,14 @@ func (n *Network) Accept(conn net.Conn) {
//glog.Infof("Sending %d messages", len(ready))

for _, msg := range ready {
if msg.Priority == 0 {
n.RecvQueue <- msg
} else {
select {
case n.RecvQueue <- msg:
default:
//glog.Errorf("recv queue full, dropping messages")
}
select {
case n.RecvQueue <- msg:
default:
return errors.New("recv queue is full")
//glog.Errorf("recv queue full, dropping messages")
}
}
return nil
}

// Wrap a session around the incoming connection.
Expand Down Expand Up @@ -482,7 +480,11 @@ func (n *Network) Accept(conn net.Conn) {
*recvWindow.Index(offset) = msg
recvMutex.Unlock()

checkRecvWindow()
err = checkRecvWindow()
if err != nil {
glog.Error(err)
incoming.Close()
}
}()

}
Expand Down

0 comments on commit 5f668fc

Please sign in to comment.