File tree Expand file tree Collapse file tree 2 files changed +40
-8
lines changed Expand file tree Collapse file tree 2 files changed +40
-8
lines changed Original file line number Diff line number Diff line change @@ -239,6 +239,10 @@ func (e connectMsgError) Temporary() bool {
239239 return false
240240}
241241
242+ func (e connectMsgError ) Timeout () bool {
243+ return false
244+ }
245+
242246type ackError struct {
243247 cause error
244248}
@@ -251,13 +255,12 @@ func (e ackError) Temporary() bool {
251255 return true
252256}
253257
254- // isTemporaryNetErr returns whether the provided error is a retriable
255- // error, according to the interface defined here:
256- // https://golang.org/pkg/net/#Error
257- func isTemporaryNetErr (err error ) bool {
258- terr , ok := err .(interface {
259- Temporary () bool
260- })
258+ func (e ackError ) Timeout () bool {
259+ return false
260+ }
261261
262- return err != nil && ok && terr .Temporary ()
262+ // isTemporaryNetErr returns whether the provided error is a retriable error.
263+ func isTemporaryNetErr (err error ) bool {
264+ var netError net.Error
265+ return err != nil && errors .As (err , & netError ) && netError .Temporary ()
263266}
Original file line number Diff line number Diff line change 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 vsock
15+
16+ import (
17+ "errors"
18+ "testing"
19+
20+ "github.com/stretchr/testify/assert"
21+ )
22+
23+ func TestTemporaryNetErr (t * testing.T ) {
24+ assert .True (t , isTemporaryNetErr (& ackError {cause : errors .New ("ack" )}))
25+
26+ assert .False (t , isTemporaryNetErr (& connectMsgError {cause : errors .New ("connect" )}))
27+ assert .False (t , isTemporaryNetErr (errors .New ("something else" )))
28+ assert .False (t , isTemporaryNetErr (nil ))
29+ }
You can’t perform that action at this time.
0 commit comments