Skip to content

Commit 54ac37d

Browse files
committed
Fix Go back-compatibility in Accept error check.
Emit the message as DEBUG, so logs avoid false positive errors. net.ErrClosed was added in Go 1.16, but this project's go.mod specifies Go 1.13. We alias Go's internal error type, to avoid the worse alternative of comparing the string of the error message. Go maintainers discuss this topic at length in golang/go#4373. Occurences of "use of closed network connection" are not an actual problem. It's advisory only, akin to io.EOF.
1 parent 46e50be commit 54ac37d

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

net_err_closed.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build !go1.16
2+
// +build !go1.16
3+
4+
package plugin
5+
6+
import _ "unsafe"
7+
8+
// NetErrClosed aliases the internal error type poll.ErrNetClosing.
9+
// FUTURE: When Go 1.16 is the minimum supported version for go-plugin, switch to net.ErrClosed.
10+
//go:linkname NetErrClosed internal/poll.ErrNetClosing
11+
var NetErrClosed error

net_err_closed_go1.16.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build go1.16
2+
// +build go1.16
3+
4+
package plugin
5+
6+
import "net"
7+
8+
var NetErrClosed = net.ErrClosed

rpc_server.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ func (s *RPCServer) Serve(lis net.Listener) {
4545
for {
4646
conn, err := lis.Accept()
4747
if err != nil {
48-
if ! errors.Is(err, net.ErrClosed) {
48+
if errors.Is(err, NetErrClosed) {
49+
log.Printf("[DEBUG] plugin: plugin server: %s", err)
50+
} else {
4951
log.Printf("[ERR] plugin: plugin server: %s", err)
5052
}
5153
return

0 commit comments

Comments
 (0)