Skip to content

Commit

Permalink
Fix Go back-compatibility in Accept error check.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tbehling committed Jan 27, 2022
1 parent 46e50be commit 54ac37d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions net_err_closed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !go1.16
// +build !go1.16

package plugin

import _ "unsafe"

// NetErrClosed aliases the internal error type poll.ErrNetClosing.
// FUTURE: When Go 1.16 is the minimum supported version for go-plugin, switch to net.ErrClosed.
//go:linkname NetErrClosed internal/poll.ErrNetClosing
var NetErrClosed error
8 changes: 8 additions & 0 deletions net_err_closed_go1.16.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build go1.16
// +build go1.16

package plugin

import "net"

var NetErrClosed = net.ErrClosed
4 changes: 3 additions & 1 deletion rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ func (s *RPCServer) Serve(lis net.Listener) {
for {
conn, err := lis.Accept()
if err != nil {
if ! errors.Is(err, net.ErrClosed) {
if errors.Is(err, NetErrClosed) {
log.Printf("[DEBUG] plugin: plugin server: %s", err)
} else {
log.Printf("[ERR] plugin: plugin server: %s", err)
}
return
Expand Down

0 comments on commit 54ac37d

Please sign in to comment.