Skip to content

Commit

Permalink
Add temporary workaround to handle net.Errors from app conn properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Dec 17, 2019
1 parent e0dda82 commit b034de6
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 159 deletions.
47 changes: 38 additions & 9 deletions pkg/app/appserver/rpc_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,34 @@ type WriteReq struct {
B []byte
}

// WriteResp contains response parameters for `Write`.
type WriteResp struct {
N int
Err string
IsNetErr bool
IsTimeoutErr bool
IsTemporaryErr bool
}

// Write writes to the connection.
func (r *RPCGateway) Write(req *WriteReq, n *int) error {
func (r *RPCGateway) Write(req *WriteReq, resp *WriteResp) error {
conn, err := r.getConn(req.ConnID)
if err != nil {
return err
}

*n, err = conn.Write(req.B)
resp.N, err = conn.Write(req.B)
if err != nil {
return err
resp.Err = err.Error()

if netErr, ok := err.(net.Error); ok {
resp.IsNetErr = true
resp.IsTemporaryErr = netErr.Temporary()
resp.IsTimeoutErr = netErr.Timeout()
}
}

// avoid error in RPC pipeline, error is included in response body
return nil
}

Expand All @@ -188,8 +204,12 @@ type ReadReq struct {

// ReadResp contains response parameters for `Read`.
type ReadResp struct {
B []byte
N int
B []byte
N int
Err string
IsNetErr bool
IsTimeoutErr bool
IsTemporaryErr bool
}

// Read reads data from connection specified by `connID`.
Expand All @@ -202,13 +222,22 @@ func (r *RPCGateway) Read(req *ReadReq, resp *ReadResp) error {
buf := make([]byte, req.BufLen)

resp.N, err = conn.Read(buf)
if err != nil {
return err
if resp.N != 0 {
resp.B = make([]byte, resp.N)
copy(resp.B, buf[:resp.N])
}

resp.B = make([]byte, resp.N)
copy(resp.B, buf[:resp.N])
if err != nil {
resp.Err = err.Error()

if netErr, ok := err.(net.Error); ok {
resp.IsNetErr = true
resp.IsTemporaryErr = netErr.Temporary()
resp.IsTimeoutErr = netErr.Timeout()
}
}

// avoid error in RPC pipeline, error is included in response body
return nil
}

Expand Down
15 changes: 11 additions & 4 deletions pkg/app/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@ type Conn struct {
// Read reads from connection.
func (c *Conn) Read(b []byte) (int, error) {
n, err := c.rpc.Read(c.id, b)
if err != nil {
return 0, err
}
/*if err != nil && err != io.EOF {
fmt.Printf("READ ERROR: %v\n", err)
return n, &net.OpError{Op: "read", Net: c.local.Network(), Source: c.local, Addr: c.remote, Err: err}
}*/

return n, err
}

// Write writes to connection.
func (c *Conn) Write(b []byte) (int, error) {
return c.rpc.Write(c.id, b)
n, err := c.rpc.Write(c.id, b)
if err != nil {
//return n, &net.OpError{Op: "write", Net: c.local.Network(), Source: c.local, Addr: c.remote, Err: err}
return n, err
}

return n, nil
}

// Close closes connection.
Expand Down
Loading

0 comments on commit b034de6

Please sign in to comment.