Commit a9d5668f authored by AlexStocks's avatar AlexStocks

Mod: defend timeout response

parent f16d6d53
......@@ -21,9 +21,10 @@ import (
)
var (
errInvalidAddress = jerrors.New("remote address invalid or empty")
errSessionNotExist = jerrors.New("session not exist")
errClientClosed = jerrors.New("client closed")
errInvalidAddress = jerrors.New("remote address invalid or empty")
errSessionNotExist = jerrors.New("session not exist")
errClientClosed = jerrors.New("client closed")
errClientReadTimeout = jerrors.New("client read timeout")
)
func init() {
......@@ -141,9 +142,18 @@ func (c *Client) Call(addr, protocol, service, method string, args interface{},
if err := c.transfer(session, b, resp); err != nil {
return jerrors.Trace(err)
}
<-resp.done
// <-resp.done
return jerrors.Trace(resp.err)
var err error
select {
case <-getty.GetTimeWheel().After(c.conf.GettySessionParam.tcpReadTimeout):
err = errClientReadTimeout
c.RemovePendingResponse(resp.seq)
case <-resp.done:
err = resp.err
}
return jerrors.Trace(err)
}
func (c *Client) Close() {
......
......@@ -49,6 +49,10 @@ var (
wheel = gxtime.NewWheel(gxtime.TimeMillisecondDuration(100), 1200) // wheel longest span is 2 minute
)
func GetTimeWheel() *gxtime.Wheel {
return wheel
}
// getty base session
type session struct {
name string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment