forked from lightninglabs/lndmon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request lightninglabs#110 from guggero/ignore-timeout
collectors: don't shut down on timeout on `GetInfo` RPC call
- Loading branch information
Showing
4 changed files
with
85 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package collectors | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
var ( | ||
// errRPCDeadlineExceeded is the error that is sent over the gRPC | ||
// interface when it's coming from the server side. The | ||
// status.FromContextError() function won't recognize it correctly | ||
// since the error sent over the wire is a string and not a structured | ||
// error anymore. | ||
errRPCDeadlineExceeded = status.Error( | ||
codes.DeadlineExceeded, context.DeadlineExceeded.Error(), | ||
) | ||
) | ||
|
||
// IsDeadlineExceeded returns true if the passed error is a gRPC error with the | ||
// context.DeadlineExceeded error as the cause. | ||
func IsDeadlineExceeded(err error) bool { | ||
if err == nil { | ||
return false | ||
} | ||
|
||
st := status.FromContextError(err) | ||
if st.Code() == codes.DeadlineExceeded { | ||
return true | ||
} | ||
|
||
if strings.Contains(err.Error(), errRPCDeadlineExceeded.Error()) { | ||
return true | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters