Skip to content

conduit bugfix: succeed close calls when init fails #1204

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

Merged
merged 1 commit into from
Aug 26, 2022

Conversation

Eric-Warehime
Copy link
Contributor

Summary

When running conduit using the indexer setup (alogd, ledger, postgresql), you will get a NPE when your algod fails to connect (traceback included below). This is because the Close function is being called and invoking function calls on objects which were never initialized (ledger, db, cancel func).

> ./cmd/conduit/conduit -d ~/.algorand/conduit/
{"__type":"Conduit","_name":"main","level":"info","msg":"Data Directory: /Users/eric/.algorand/conduit/ ","time":"2022-08-26T12:47:57-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Auto-loading Conduit Configuration: /Users/eric/.algorand/conduit/conduit.yml","time":"2022-08-26T12:47:57-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Log level set to: info","time":"2022-08-26T12:47:57-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Conduit configuration is valid","time":"2022-08-26T12:47:57-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Found Importer: algod","time":"2022-08-26T12:47:57-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Found Processor: block_evaluator","time":"2022-08-26T12:47:57-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Found Exporter: postgresql","time":"2022-08-26T12:47:57-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Starting Pipeline Initialization","time":"2022-08-26T12:47:57-07:00"}
{"__type":"Conduit","_name":"main","level":"error","msg":"Pipeline start failure: Pipeline.Start(): could not initialize Exporter (postgresql): connect failure constructing db, postgres: connecting to postgres: failed to connect to `host=localhost user=algorand database=indexer_db`: dial error (dial tcp 127.0.0.1:45432: connect: connection refused)","time":"2022-08-26T12:47:57-07:00"}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10357ae04]

goroutine 1 [running]:
github.com/algorand/indexer/importers/algod.(*algodImporter).Close(0x14000141ae0)
   /Users/eric/go/src/github.com/algorand/indexer/importers/algod/algod_importer.go:100 +0x24
github.com/algorand/indexer/conduit.(*pipelineImpl).Stop(0x140001d6c00)
   /Users/eric/go/src/github.com/algorand/indexer/conduit/pipeline.go:196 +0x44
main.runConduitCmdWithConfig.func1({0x103c0f088, 0x140001d6c00})
   /Users/eric/go/src/github.com/algorand/indexer/cmd/conduit/main.go:90 +0x30
main.runConduitCmdWithConfig(0x14000212e40)
   /Users/eric/go/src/github.com/algorand/indexer/cmd/conduit/main.go:100 +0x448
main.conduitCmd.func1(0x140006c3180, {0x1400011f0c0, 0x0, 0x2})
   /Users/eric/go/src/github.com/algorand/indexer/cmd/conduit/main.go:115 +0x28
github.com/spf13/cobra.(*Command).execute(0x140006c3180, {0x140000321c0, 0x2, 0x2})
   /Users/eric/.asdf/installs/golang/1.17.9/packages/pkg/mod/github.com/spf13/[email protected]/command.go:856 +0x668
github.com/spf13/cobra.(*Command).ExecuteC(0x140006c3180)
   /Users/eric/.asdf/installs/golang/1.17.9/packages/pkg/mod/github.com/spf13/[email protected]/command.go:974 +0x410
github.com/spf13/cobra.(*Command).Execute(...)
   /Users/eric/.asdf/installs/golang/1.17.9/packages/pkg/mod/github.com/spf13/[email protected]/command.go:902
main.main()

Test Plan

Failures now properly show error instead of NPE panic.

> ./cmd/conduit/conduit -d ~/.algorand/conduit/
{"__type":"Conduit","_name":"main","level":"info","msg":"Data Directory: /Users/eric/.algorand/conduit/ ","time":"2022-08-26T13:19:23-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Auto-loading Conduit Configuration: /Users/eric/.algorand/conduit/conduit.yml","time":"2022-08-26T13:19:23-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Log level set to: info","time":"2022-08-26T13:19:23-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Conduit configuration is valid","time":"2022-08-26T13:19:23-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Found Importer: algod","time":"2022-08-26T13:19:23-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Found Processor: block_evaluator","time":"2022-08-26T13:19:23-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Found Exporter: postgresql","time":"2022-08-26T13:19:23-07:00"}
{"__type":"Conduit","_name":"main","level":"info","msg":"Starting Pipeline Initialization","time":"2022-08-26T13:19:23-07:00"}
{"__type":"Conduit","_name":"main","level":"error","msg":"Pipeline start failure: Pipeline.Start(): could not initialize Exporter (postgresql): connect failure constructing db, postgres: connecting to postgres: failed to connect to `host=localhost user=algorand database=indexer_db`: dial error (dial tcp 127.0.0.1:45432: connect: connection refused)","time":"2022-08-26T13:19:23-07:00"}
Error: Pipeline.Start(): could not initialize Exporter (postgresql): connect failure constructing db, postgres: connecting to postgres: failed to connect to `host=localhost user=algorand database=indexer_db`: dial error (dial tcp 127.0.0.1:45432: connect: connection refused)
Usage:
  conduit [flags]

Flags:
  -d, --data-dir string   set the data directory for the conduit binary
  -h, --help              help for conduit

ERRO[0000] Pipeline.Start(): could not initialize Exporter (postgresql): connect failure constructing db, postgres: connecting to postgres: failed to connect to `host=localhost user=algorand database=indexer_db`: dial error (dial tcp 127.0.0.1:45432: connect: connection refused) 

@Eric-Warehime Eric-Warehime added the Not-Yet-Enabled Feature is not yet enabled at this time label Aug 26, 2022
@codecov
Copy link

codecov bot commented Aug 26, 2022

Codecov Report

❗ No coverage uploaded for pull request base (conduit@adbae7e). Click here to learn what that means.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             conduit    #1204   +/-   ##
==========================================
  Coverage           ?   60.10%           
==========================================
  Files              ?       64           
  Lines              ?     8901           
  Branches           ?        0           
==========================================
  Hits               ?     5350           
  Misses             ?     3077           
  Partials           ?      474           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Eric-Warehime Eric-Warehime added the Skip-Release-Notes Reserved for PRs which do not need to be included in Release Notes label Aug 26, 2022
@Eric-Warehime Eric-Warehime changed the title bugfix: succeed close calls when init fails conduit bugfix: succeed close calls when init fails Aug 26, 2022
@Eric-Warehime Eric-Warehime merged commit bf8b441 into algorand:conduit Aug 26, 2022
@Eric-Warehime Eric-Warehime deleted the nil-close-bug branch August 26, 2022 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Not-Yet-Enabled Feature is not yet enabled at this time Skip-Release-Notes Reserved for PRs which do not need to be included in Release Notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants