forked from cockroachdb/cockroach
-
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 cockroachdb#72004 from rafiss/backport21.2-71940
release-21.2: sql/pgwire: handle broken connection better in processing loop
- Loading branch information
Showing
5 changed files
with
126 additions
and
8 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
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,93 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package netutil | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net" | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cmux" | ||
"github.com/cockroachdb/cockroach/pkg/util/contextutil" | ||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
func TestIsClosedConnection(t *testing.T) { | ||
for _, tc := range []struct { | ||
err error | ||
isClosedError bool | ||
}{ | ||
{ | ||
fmt.Errorf("an error"), | ||
false, | ||
}, | ||
{ | ||
net.ErrClosed, | ||
true, | ||
}, | ||
{ | ||
cmux.ErrListenerClosed, | ||
true, | ||
}, | ||
{ | ||
grpc.ErrServerStopped, | ||
true, | ||
}, | ||
{ | ||
io.EOF, | ||
true, | ||
}, | ||
{ | ||
// TODO(rafi): should this be treated the same as EOF? | ||
io.ErrUnexpectedEOF, | ||
false, | ||
}, | ||
{ | ||
&net.AddrError{Err: "addr", Addr: "err"}, | ||
true, | ||
}, | ||
{ | ||
syscall.ECONNRESET, | ||
true, | ||
}, | ||
{ | ||
syscall.EADDRINUSE, | ||
true, | ||
}, | ||
{ | ||
syscall.ECONNABORTED, | ||
true, | ||
}, | ||
{ | ||
syscall.ECONNREFUSED, | ||
true, | ||
}, | ||
{ | ||
syscall.EBADMSG, | ||
true, | ||
}, | ||
{ | ||
syscall.EINTR, | ||
false, | ||
}, | ||
{ | ||
&contextutil.TimeoutError{}, | ||
false, | ||
}, | ||
} { | ||
assert.Equalf(t, tc.isClosedError, IsClosedConnection(tc.err), | ||
"expected %q to be evaluated as %v", tc.err, tc.isClosedError, | ||
) | ||
} | ||
} |