Skip to content

Commit 6622850

Browse files
committed
improved logging for IPC connection lifetime management
1 parent 5757a0e commit 6622850

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

rpc/comms/comms.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type EthereumClient interface {
4343
SupportedModules() (map[string]string, error)
4444
}
4545

46-
func handle(conn net.Conn, api shared.EthereumApi, c codec.Codec) {
46+
func handle(id int, conn net.Conn, api shared.EthereumApi, c codec.Codec) {
4747
codec := c.New(conn)
4848

4949
for {
@@ -52,8 +52,8 @@ func handle(conn net.Conn, api shared.EthereumApi, c codec.Codec) {
5252
codec.Close()
5353
return
5454
} else if err != nil {
55-
glog.V(logger.Error).Infof("comms recv err - %v\n", err)
5655
codec.Close()
56+
glog.V(logger.Debug).Infof("Closed IPC Conn %06d recv err - %v\n", id, err)
5757
return
5858
}
5959

@@ -71,8 +71,8 @@ func handle(conn net.Conn, api shared.EthereumApi, c codec.Codec) {
7171

7272
err = codec.WriteResponse(responses[:responseCount])
7373
if err != nil {
74-
glog.V(logger.Error).Infof("comms send err - %v\n", err)
7574
codec.Close()
75+
glog.V(logger.Debug).Infof("Closed IPC Conn %06d send err - %v\n", id, err)
7676
return
7777
}
7878
} else {
@@ -82,8 +82,8 @@ func handle(conn net.Conn, api shared.EthereumApi, c codec.Codec) {
8282
rpcResponse = shared.NewRpcResponse(requests[0].Id, requests[0].Jsonrpc, res, err)
8383
err = codec.WriteResponse(rpcResponse)
8484
if err != nil {
85-
glog.V(logger.Error).Infof("comms send err - %v\n", err)
8685
codec.Close()
86+
glog.V(logger.Debug).Infof("Closed IPC Conn %06d send err - %v\n", id, err)
8787
return
8888
}
8989
}

rpc/comms/ipc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package comms
22

33
import (
44
"fmt"
5+
"math/rand"
56
"net"
67

78
"encoding/json"
@@ -95,3 +96,7 @@ func NewIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) {
9596
func StartIpc(cfg IpcConfig, codec codec.Codec, offeredApi shared.EthereumApi) error {
9697
return startIpc(cfg, codec, offeredApi)
9798
}
99+
100+
func newIpcConnId() int {
101+
return rand.Int() % 1000000
102+
}

rpc/comms/ipc_unix.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ func startIpc(cfg IpcConfig, codec codec.Codec, api shared.EthereumApi) error {
4848
continue
4949
}
5050

51-
go handle(conn, api, codec)
51+
id := newIpcConnId()
52+
glog.V(logger.Debug).Infof("New IPC connection with id %06d started\n", id)
53+
54+
go handle(id, conn, api, codec)
5255
}
5356

5457
os.Remove(cfg.Endpoint)

rpc/comms/ipc_windows.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -667,13 +667,16 @@ func startIpc(cfg IpcConfig, codec codec.Codec, api shared.EthereumApi) error {
667667
glog.V(logger.Error).Infof("Error accepting ipc connection - %v\n", err)
668668
continue
669669
}
670-
671-
go handle(conn, api, codec)
672-
}
673-
674-
os.Remove(cfg.Endpoint)
675-
}()
676-
670+
671+
id := newIpcConnId()
672+
glog.V(logger.Debug).Infof("New IPC connection with id %06d started\n", id)
673+
674+
go handle(id, conn, api, codec)
675+
}
676+
677+
os.Remove(cfg.Endpoint)
678+
}()
679+
677680
glog.V(logger.Info).Infof("IPC service started (%s)\n", cfg.Endpoint)
678681

679682
return nil

0 commit comments

Comments
 (0)