Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add panic recovers #1251

Merged
merged 2 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/conduit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func init() {

// runConduitCmdWithConfig run the main logic with a supplied conduit config
func runConduitCmdWithConfig(cfg *conduit.Config) error {
defer conduit.HandlePanic(logger)

// From docs:
// BindEnv takes one or more parameters. The first parameter is the key name, the rest are the name of the
Expand Down
1 change: 1 addition & 0 deletions cmd/conduit/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/require"
)

// TestInitDataDirectory tests the initialization of the data directory
func TestInitDataDirectory(t *testing.T) {
verifyFile := func(file string) {
require.FileExists(t, file)
Expand Down
10 changes: 10 additions & 0 deletions conduit/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package conduit

import log "github.com/sirupsen/logrus"

// HandlePanic function to log panics in a common way
func HandlePanic(logger *log.Logger) {
if r := recover(); r != nil {
logger.Panicf("conduit pipeline experienced a panic: %v", r)
}
}
2 changes: 2 additions & 0 deletions conduit/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ func (p *pipelineImpl) Start() {
p.wg.Add(1)
go func() {
defer p.wg.Done()
// We need to add a separate recover function here since it launches its own go-routine
defer HandlePanic(p.logger)
for {
pipelineRun:
select {
Expand Down