Skip to content

Commit 39a4233

Browse files
committed
Fix panic in agent
Previously, there was an issue where the agent could panic while attempting to determine if an error was temporary. Before the change, in `agent/exec/errors.go`, the function `IsTemporary` attempted to drill down to a root cause by iterating through the causes of an error by calling `errors.Cause`. If an error has no cause, then `errors.Cause` returns that same error. The issue is that somewhere in the depths of some code, it was posssible for the error to have an underlying type that was non-comparable; for example, maps and slices are uncomparable types. This would cause a panic, as the uncomparable type cannot be compared even to itself. However, one can see that `errors.Cause` has its own loop, and drills down to the root cause in its own way. There is no need for us to iterate here. Instead, we can just take a look at the error itself, and then take a look at its cause once. If neither is temporary, the error is not temporary, and we have nothing to worry about. Signed-off-by: Drew Erny <[email protected]>
1 parent 516e8f3 commit 39a4233

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

agent/exec/errors.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,14 @@ func (t temporary) Temporary() bool { return true }
7070
// IsTemporary returns true if the error or a recursive cause returns true for
7171
// temporary.
7272
func IsTemporary(err error) bool {
73-
for err != nil {
74-
if tmp, ok := err.(Temporary); ok && tmp.Temporary() {
75-
return true
76-
}
73+
if tmp, ok := err.(Temporary); ok && tmp.Temporary() {
74+
return true
75+
}
7776

78-
cause := errors.Cause(err)
79-
if cause == err {
80-
break
81-
}
77+
cause := errors.Cause(err)
8278

83-
err = cause
79+
if tmp, ok := cause.(Temporary); ok && tmp.Temporary() {
80+
return true
8481
}
8582

8683
return false

0 commit comments

Comments
 (0)