Skip to content

Commit

Permalink
make sure everything is stopped before closing db and redis pools
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed Aug 23, 2017
1 parent d8ff1a3 commit cb47efb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
12 changes: 6 additions & 6 deletions backends/rapidpro/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,18 +383,18 @@ func (b *backend) Start() error {

// Stop stops our RapidPro backend, closing our db and redis connections
func (b *backend) Stop() error {
if b.db != nil {
b.db.Close()
}

b.redisPool.Close()

// close our stop channel
close(b.stopChan)

// wait for our threads to exit
b.waitGroup.Wait()

// close our db and redis pool
if b.db != nil {
b.db.Close()
}
b.redisPool.Close()

return nil
}

Expand Down
7 changes: 4 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,16 @@ func (s *server) Stop() error {
log.WithField("state", "stopping").WithError(err).Error("error shutting down server")
}

// stop everything
s.stopped = true
close(s.stopChan)

// stop our backend
err := s.backend.Stop()
if err != nil {
return err
}

s.stopped = true
close(s.stopChan)

// stop our librato sender
librato.Default.Stop()

Expand Down

0 comments on commit cb47efb

Please sign in to comment.