Skip to content

Commit

Permalink
[FAB-16879] Add stack trace to couchdb http errors (#1048)
Browse files Browse the repository at this point in the history
If there is http error calling couchdb, no context was provided
to higher level code that handles the errors.

This change adds stack trace to the http error at the point that the error
is raised, so that admins can identify what was going on upon hitting the error.
In most places, the higher level error handlers are already printing stack
trace, if available. This change adds the stack trace printing to OpenLeder()
error handling, e.g. if there is an error during recommit lost block path.

Also, for each of the points in ledger code where go routines are used,
if stack trace was added in the go routine error, the stack would only
be available from the point the go routine was called and lower. This
is resolved by also adding stack trace to errors that are returned from
go routines.

Signed-off-by: David Enyeart <enyeart@us.ibm.com>
  • Loading branch information
denyeart authored Apr 10, 2020
1 parent c68ee5c commit f9e80e8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package statecouchdb

import (
"sync"

"github.com/pkg/errors"
)

// batch is executed in a separate goroutine.
Expand Down Expand Up @@ -40,7 +42,7 @@ func executeBatches(batches []batch) error {
}
batchWG.Wait()
if len(errsChan) > 0 {
return <-errsChan
return errors.WithStack(<-errsChan)
}
return nil
}
2 changes: 1 addition & 1 deletion core/ledger/util/couchdb/couchdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,7 @@ func (couchInstance *CouchInstance) handleRequest(ctx context.Context, method, d

//if a golang http error is still present after retries are exhausted, return the error
if errResp != nil {
return nil, couchDBReturn, errResp
return nil, couchDBReturn, errors.Wrap(errResp, "http error calling couchdb")
}

//This situation should not occur according to the golang spec.
Expand Down
2 changes: 1 addition & 1 deletion core/peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ 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.Errorf("Failed to load ledger %s(%s)", cid, err)
peerLogger.Errorf("Failed to load ledger %s(%+v)", cid, err)
peerLogger.Debugf("Error while loading ledger %s with message %s. We continue to the next ledger rather than abort.", cid, err)
continue
}
Expand Down
2 changes: 1 addition & 1 deletion integration/e2e/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var _ = Describe("Health", func() {
statusCode, status = DoHealthCheck(authClient, healthURL)
Expect(status.Status).To(Equal("Service Unavailable"))
Expect(status.FailedChecks[0].Component).To(Equal("couchdb"))
Expect(status.FailedChecks[0].Reason).Should((HavePrefix(fmt.Sprintf("failed to connect to couch db [Head http://%s: dial tcp %s: ", couchAddr, couchAddr))))
Expect(status.FailedChecks[0].Reason).Should((HavePrefix(fmt.Sprintf("failed to connect to couch db [http error calling couchdb: Head http://%s: dial tcp %s: ", couchAddr, couchAddr))))
})
})
})
Expand Down

0 comments on commit f9e80e8

Please sign in to comment.