Commit c458d3ae authored by David Enyeart's avatar David Enyeart
Browse files

[FAB-14501] Handling of CouchDB connection errors

There is a regression caused by https://gerrit.hyperledger.org/r/27558


where the error caused by connection failure to CouchDB does not get handled.

This leads to a nil pointer panic when the nil vdbProvider tries to get
a handle to a database.

This change will handle the CouchDB connection error gracefully and panic
the peer with a good error message (e.g. connection problem,
username/password problem) as was done in prior releases.

Change-Id: I5f459ab92c189de49442aef24fcd80abcd3a0391
Signed-off-by: default avatarDavid Enyeart <enyeart@us.ibm.com>
parent a27f7208
......@@ -70,13 +70,16 @@ func initialize(initializer *Initializer) {
if err != nil {
panic(errors.WithMessage(err, "Error in instantiating ledger provider"))
}
provider.Initialize(&ledger.Initializer{
err = provider.Initialize(&ledger.Initializer{
StateListeners: finalStateListeners,
DeployedChaincodeInfoProvider: initializer.DeployedChaincodeInfoProvider,
MembershipInfoProvider: initializer.MembershipInfoProvider,
MetricsProvider: initializer.MetricsProvider,
HealthCheckRegistry: initializer.HealthCheckRegistry,
})
if err != nil {
panic(errors.WithMessage(err, "Error initializing ledger provider"))
}
ledgerProvider = provider
logger.Info("ledger mgmt initialized")
}
......
......@@ -232,18 +232,18 @@ func Initialize(init func(string), ccp ccprovider.ChaincodeProvider, sccp sysccp
for _, cid := range ledgerIds {
peerLogger.Infof("Loading chain %s", cid)
if ledger, err = ledgermgmt.OpenLedger(cid); err != nil {
peerLogger.Warningf("Failed to load ledger %s(%s)", cid, err)
peerLogger.Errorf("Failed to load ledger %s(%s)", cid, err)
peerLogger.Debugf("Error while loading ledger %s with message %s. We continue to the next ledger rather than abort.", cid, err)
continue
}
if cb, err = getCurrConfigBlockFromLedger(ledger); err != nil {
peerLogger.Warningf("Failed to find config block on ledger %s(%s)", cid, err)
peerLogger.Errorf("Failed to find config block on ledger %s(%s)", cid, err)
peerLogger.Debugf("Error while looking for config block on ledger %s with message %s. We continue to the next ledger rather than abort.", cid, err)
continue
}
// Create a chain if we get a valid ledger with config block
if err = createChain(cid, ledger, cb, ccp, sccp, pm); err != nil {
peerLogger.Warningf("Failed to load chain %s(%s)", cid, err)
peerLogger.Errorf("Failed to load chain %s(%s)", cid, err)
peerLogger.Debugf("Error reloading chain %s with message %s. We continue to the next chain rather than abort.", cid, err)
continue
}
......
......@@ -571,7 +571,7 @@ ledger:
# This username must have read and write authority on CouchDB
username:
# The password is recommended to pass as an environment variable
# during start up (eg LEDGER_COUCHDBCONFIG_PASSWORD).
# during start up (eg CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD).
# If it is stored here, the file must be access control protected
# to prevent unintended users from discovering the password.
password:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment