-
Notifications
You must be signed in to change notification settings - Fork 92
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 IndexerDb.Close()
#801
Conversation
4b9df9c
to
8569dd2
Compare
Codecov Report
@@ Coverage Diff @@
## develop #801 +/- ##
===========================================
+ Coverage 58.83% 58.84% +0.01%
===========================================
Files 29 29
Lines 4059 4060 +1
===========================================
+ Hits 2388 2389 +1
Misses 1374 1374
Partials 297 297
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a couple small things to address.
imp := importer.NewImporter(db) | ||
handler := func(ctx context.Context, block *rpcs.EncodedBlockCert) error { | ||
return handleBlock(block, &imp) | ||
} | ||
bot.SetBlockHandler(handler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I slightly prefer the interface object over the closure here (up to you though).
AddBlockHandler -> SetBlockHandler is a nice simplification
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Interface objects are harder to construct at the user side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The terseness mainly, you could create/set it in one line if you wanted. Here you must create the importer object separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about terseness. With a closure, looking at the function signature, you immediately see what the closure is. Plus, an interface is a set of functions. That's redundant.
return fmt.Errorf("Run() err: %w", err) | ||
case err := <-ch1: | ||
cancelFunc() | ||
<-ch0 | ||
return fmt.Errorf("Run() err: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Disambiguate the errors, more descriptive channel names would also be helpful.
return fmt.Errorf("Run() err: %w", err) | |
case err := <-ch1: | |
cancelFunc() | |
<-ch0 | |
return fmt.Errorf("Run() err: %w", err) | |
return fmt.Errorf("Run() processQueue err: %w", err) | |
case err := <-ch1: | |
cancelFunc() | |
<-ch0 | |
return fmt.Errorf("Run() mainLoop err: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the err
objects will tell where they come from
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the err objects
willshould tell where they come from
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But they do. You can check mainLoop()
and processQueue()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
Thanks! |
Summary
When running test with the
--test-pg
flag, we open many database connections without closing them. This leads to the database refusing new connections.This PR adds
IndexerDb.Close()
function that closes all active connections to the database.