Browse Source

Protect panicking poll loops from taking down the entire process

kegan/service-isolation
Kegan Dougal 8 years ago
parent
commit
7ab9794623
  1. 10
      src/github.com/matrix-org/go-neb/polling/polling.go

10
src/github.com/matrix-org/go-neb/polling/polling.go

@ -5,6 +5,7 @@ import (
"github.com/matrix-org/go-neb/clients"
"github.com/matrix-org/go-neb/database"
"github.com/matrix-org/go-neb/types"
"runtime/debug"
"sync"
"time"
)
@ -71,6 +72,15 @@ func pollLoop(service types.Service, ts int64) {
"service_id": service.ServiceID(),
"service_type": service.ServiceType(),
})
defer func() {
if r := recover(); r != nil {
logger.WithField("panic", r).Errorf(
"pollLoop panicked!\n%s", debug.Stack(),
)
}
}()
poller, ok := service.(types.Poller)
if !ok {
logger.Error("Service is not a Poller.")

Loading…
Cancel
Save