Skip to content

Commit

Permalink
Merge "fix DeliverService stop"
Browse files Browse the repository at this point in the history
  • Loading branch information
Srinivasan Muralidharan authored and Gerrit Code Review committed Dec 1, 2016
2 parents 5816af2 + 8e868b8 commit 2570f8f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion core/committer/noopssinglechain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package noopssinglechain

import (
"sync/atomic"
"time"

"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -61,6 +62,7 @@ type DeliverService struct {
gossip gossip.Gossip
conn *grpc.ClientConn

stopFlag int32
stopChan chan bool
}

Expand Down Expand Up @@ -173,6 +175,8 @@ func (d *DeliverService) Start() {

// Stop all service and release resources
func (d *DeliverService) Stop() {
atomic.StoreInt32(&d.stopFlag, 1)
d.stopDeliver()
d.stopChan <- true
d.stateProvider.Stop()
d.gossip.Stop()
Expand Down Expand Up @@ -214,13 +218,23 @@ func (d *DeliverService) seekLatestFromCommitter(height uint64) error {
})
}

// Internal function to check whenever we need to finish listening
// for new messages to arrive
func (d *DeliverService) isDone() bool {

return atomic.LoadInt32(&d.stopFlag) == 1
}

func (d *DeliverService) readUntilClose() {
for {
msg, err := d.client.Recv()
if err != nil {
logger.Warningf("Receive error: %s", err.Error())
if d.isDone() {
<-d.stopChan
}
return
}

switch t := msg.Type.(type) {
case *orderer.DeliverResponse_Error:
if t.Error == common.Status_SUCCESS {
Expand Down

0 comments on commit 2570f8f

Please sign in to comment.