Skip to content

Commit

Permalink
save current request along with the client connection
Browse files Browse the repository at this point in the history
so it can be printed on timeouts.
  • Loading branch information
sni committed Sep 19, 2023
1 parent 6ce7e4c commit 5472bfa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lmd/client_con.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ClientConnection struct {
logSlowQueryThreshold int
logHugeQueryThreshold int
queryStats *QueryStats
curRequest *Request
}

// NewClientConnection creates a new client connection object
Expand Down Expand Up @@ -70,6 +71,9 @@ func (cl *ClientConnection) Handle() {
logWith(ctx).Debugf("closing keep alive connection (timeout: %s)", time.Duration(cl.listenTimeout)*time.Second)
} else {
logWith(ctx).Warnf("request timed out (timeout: %s)", time.Duration(cl.listenTimeout)*time.Second)
if cl.curRequest != nil {
logWith(ctx).Warnf("", cl.curRequest.String())
}
}
}
cl.connection.Close()
Expand Down Expand Up @@ -139,9 +143,13 @@ func (cl *ClientConnection) processRequests(ctx context.Context, reqs []*Request
if len(reqs) == 0 {
return
}
defer func() {
cl.curRequest = nil
}()
commandsByPeer := make(map[string][]string)
for _, req := range reqs {
cl.keepAlive = req.KeepAlive
cl.curRequest = req
reqctx := context.WithValue(ctx, CtxRequest, req.ID())
t1 := time.Now()
if req.Command != "" {
Expand Down Expand Up @@ -191,6 +199,10 @@ func (cl *ClientConnection) processRequests(ctx context.Context, reqs []*Request
}

func (cl *ClientConnection) processRequest(ctx context.Context, req *Request) (size int64, err error) {
cl.curRequest = req
defer func() {
cl.curRequest = nil
}()
size, err = req.BuildResponseSend(ctx, cl.connection)
if err != nil {
if netErr, ok := err.(net.Error); ok {
Expand Down

0 comments on commit 5472bfa

Please sign in to comment.