aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorFelix Lange <fjl@users.noreply.github.com>2018-04-18 18:27:20 +0800
committerGitHub <noreply@github.com>2018-04-18 18:27:20 +0800
commit52b046c9b6a0f6a280ff797f90784f76bfd310b9 (patch)
tree709ce3f7e873e47bdac72ab4f9935cf7b3108c4b /rpc
parent661f5f3dac23939630e3bf2f9ed2bf1bfb26e990 (diff)
downloadgo-tangerine-52b046c9b6a0f6a280ff797f90784f76bfd310b9.tar.gz
go-tangerine-52b046c9b6a0f6a280ff797f90784f76bfd310b9.tar.zst
go-tangerine-52b046c9b6a0f6a280ff797f90784f76bfd310b9.zip
rpc: clean up IPC handler (#16524)
This avoids logging accept errors on shutdown and removes a bit of duplication. It also fixes some goimports lint warnings.
Diffstat (limited to 'rpc')
-rw-r--r--rpc/client.go2
-rw-r--r--rpc/endpoints.go36
-rw-r--r--rpc/ipc.go15
3 files changed, 16 insertions, 37 deletions
diff --git a/rpc/client.go b/rpc/client.go
index 68745c6cb..77b4d5ee0 100644
--- a/rpc/client.go
+++ b/rpc/client.go
@@ -25,6 +25,7 @@ import (
"fmt"
"net"
"net/url"
+ "os"
"reflect"
"strconv"
"strings"
@@ -33,7 +34,6 @@ import (
"time"
"github.com/ethereum/go-ethereum/log"
- "os"
)
var (
diff --git a/rpc/endpoints.go b/rpc/endpoints.go
index 9ba2ed970..692c62d3a 100644
--- a/rpc/endpoints.go
+++ b/rpc/endpoints.go
@@ -17,8 +17,9 @@
package rpc
import (
- "github.com/ethereum/go-ethereum/log"
"net"
+
+ "github.com/ethereum/go-ethereum/log"
)
// StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules
@@ -81,9 +82,9 @@ func StartWSEndpoint(endpoint string, apis []API, modules []string, wsOrigins []
}
-// StartIPCEndpoint starts an IPC endpoint
-func StartIPCEndpoint(isClosedFn func() bool, ipcEndpoint string, apis []API) (net.Listener, *Server, error) {
- // Register all the APIs exposed by the services
+// StartIPCEndpoint starts an IPC endpoint.
+func StartIPCEndpoint(ipcEndpoint string, apis []API) (net.Listener, *Server, error) {
+ // Register all the APIs exposed by the services.
handler := NewServer()
for _, api := range apis {
if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
@@ -91,30 +92,11 @@ func StartIPCEndpoint(isClosedFn func() bool, ipcEndpoint string, apis []API) (n
}
log.Debug("IPC registered", "namespace", api.Namespace)
}
- // All APIs registered, start the IPC listener
- var (
- listener net.Listener
- err error
- )
- if listener, err = CreateIPCListener(ipcEndpoint); err != nil {
+ // All APIs registered, start the IPC listener.
+ listener, err := ipcListen(ipcEndpoint)
+ if err != nil {
return nil, nil, err
}
- go func() {
- for {
- conn, err := listener.Accept()
- if err != nil {
- // Terminate if the listener was closed
- if isClosedFn() {
- log.Info("IPC closed", "err", err)
- } else {
- // Not closed, just some error; report and continue
- log.Error("IPC accept failed", "err", err)
- }
- continue
- }
- go handler.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions)
- }
- }()
-
+ go handler.ServeListener(listener)
return listener, handler, nil
}
diff --git a/rpc/ipc.go b/rpc/ipc.go
index 8de18a56f..b05e503d7 100644
--- a/rpc/ipc.go
+++ b/rpc/ipc.go
@@ -18,26 +18,23 @@ package rpc
import (
"context"
- "fmt"
"net"
"github.com/ethereum/go-ethereum/log"
+ "github.com/ethereum/go-ethereum/p2p/netutil"
)
-// CreateIPCListener creates an listener, on Unix platforms this is a unix socket, on
-// Windows this is a named pipe
-func CreateIPCListener(endpoint string) (net.Listener, error) {
- return ipcListen(endpoint)
-}
-
// ServeListener accepts connections on l, serving JSON-RPC on them.
func (srv *Server) ServeListener(l net.Listener) error {
for {
conn, err := l.Accept()
- if err != nil {
+ if netutil.IsTemporaryError(err) {
+ log.Warn("RPC accept error", "err", err)
+ continue
+ } else if err != nil {
return err
}
- log.Trace(fmt.Sprint("accepted conn", conn.RemoteAddr()))
+ log.Trace("Accepted connection", "addr", conn.RemoteAddr())
go srv.ServeCodec(NewJSONCodec(conn), OptionMethodInvocation|OptionSubscriptions)
}
}