Skip to content

Commit 6cc5c69

Browse files
committed
isTemporaryNetErr didn't work when the error was wrapped
Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 9acc0ad commit 6cc5c69

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

internal/vm/vsock.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ func (e vsockAckError) Temporary() bool {
314314
// error, according to the interface defined here:
315315
// https://golang.org/pkg/net/#Error
316316
func isTemporaryNetErr(err error) bool {
317-
terr, ok := err.(interface {
317+
type tempError interface {
318318
Temporary() bool
319-
})
320-
321-
return err != nil && ok && terr.Temporary()
319+
}
320+
var terr tempError
321+
return err != nil && errors.As(err, &terr) && terr.Temporary()
322322
}

internal/vm/vsock_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package vm
15+
16+
import (
17+
"errors"
18+
"testing"
19+
20+
"github.com/stretchr/testify/assert"
21+
)
22+
23+
func TestTemporaryNetErr(t *testing.T) {
24+
assert.False(t, isTemporaryNetErr(nil))
25+
assert.False(t, isTemporaryNetErr(errors.New("hello")))
26+
assert.True(t, isTemporaryNetErr(&vsockAckError{cause: errors.New("hello")}))
27+
}

0 commit comments

Comments
 (0)