improved logging for IPC connection lifetime management
This commit is contained in:
parent
5757a0edb5
commit
662285074e
@ -43,7 +43,7 @@ type EthereumClient interface {
|
|||||||
SupportedModules() (map[string]string, error)
|
SupportedModules() (map[string]string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handle(conn net.Conn, api shared.EthereumApi, c codec.Codec) {
|
func handle(id int, conn net.Conn, api shared.EthereumApi, c codec.Codec) {
|
||||||
codec := c.New(conn)
|
codec := c.New(conn)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@ -52,8 +52,8 @@ func handle(conn net.Conn, api shared.EthereumApi, c codec.Codec) {
|
|||||||
codec.Close()
|
codec.Close()
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
glog.V(logger.Error).Infof("comms recv err - %v\n", err)
|
|
||||||
codec.Close()
|
codec.Close()
|
||||||
|
glog.V(logger.Debug).Infof("Closed IPC Conn %06d recv err - %v\n", id, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,8 +71,8 @@ func handle(conn net.Conn, api shared.EthereumApi, c codec.Codec) {
|
|||||||
|
|
||||||
err = codec.WriteResponse(responses[:responseCount])
|
err = codec.WriteResponse(responses[:responseCount])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(logger.Error).Infof("comms send err - %v\n", err)
|
|
||||||
codec.Close()
|
codec.Close()
|
||||||
|
glog.V(logger.Debug).Infof("Closed IPC Conn %06d send err - %v\n", id, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -82,8 +82,8 @@ func handle(conn net.Conn, api shared.EthereumApi, c codec.Codec) {
|
|||||||
rpcResponse = shared.NewRpcResponse(requests[0].Id, requests[0].Jsonrpc, res, err)
|
rpcResponse = shared.NewRpcResponse(requests[0].Id, requests[0].Jsonrpc, res, err)
|
||||||
err = codec.WriteResponse(rpcResponse)
|
err = codec.WriteResponse(rpcResponse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(logger.Error).Infof("comms send err - %v\n", err)
|
|
||||||
codec.Close()
|
codec.Close()
|
||||||
|
glog.V(logger.Debug).Infof("Closed IPC Conn %06d send err - %v\n", id, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package comms
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -95,3 +96,7 @@ func NewIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) {
|
|||||||
func StartIpc(cfg IpcConfig, codec codec.Codec, offeredApi shared.EthereumApi) error {
|
func StartIpc(cfg IpcConfig, codec codec.Codec, offeredApi shared.EthereumApi) error {
|
||||||
return startIpc(cfg, codec, offeredApi)
|
return startIpc(cfg, codec, offeredApi)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newIpcConnId() int {
|
||||||
|
return rand.Int() % 1000000
|
||||||
|
}
|
||||||
|
@ -48,7 +48,10 @@ func startIpc(cfg IpcConfig, codec codec.Codec, api shared.EthereumApi) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
go handle(conn, api, codec)
|
id := newIpcConnId()
|
||||||
|
glog.V(logger.Debug).Infof("New IPC connection with id %06d started\n", id)
|
||||||
|
|
||||||
|
go handle(id, conn, api, codec)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Remove(cfg.Endpoint)
|
os.Remove(cfg.Endpoint)
|
||||||
|
@ -668,7 +668,10 @@ func startIpc(cfg IpcConfig, codec codec.Codec, api shared.EthereumApi) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
go handle(conn, api, codec)
|
id := newIpcConnId()
|
||||||
|
glog.V(logger.Debug).Infof("New IPC connection with id %06d started\n", id)
|
||||||
|
|
||||||
|
go handle(id, conn, api, codec)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Remove(cfg.Endpoint)
|
os.Remove(cfg.Endpoint)
|
||||||
|
Loading…
Reference in New Issue
Block a user