Fix hang on empty response

This commit is contained in:
tidwall 2022-09-24 07:24:04 -07:00
parent a824d58419
commit 2b6ab4368a
1 changed files with 8 additions and 14 deletions

View File

@ -947,7 +947,7 @@ func (s *Server) handleInputCommand(client *Client, msg *Message) error {
}
}
res = NOMessage
err = writeErr("timeout")
err = errTimeout
}
}()
}
@ -975,23 +975,17 @@ func (s *Server) handleInputCommand(client *Client, msg *Message) error {
return err
}
}
if !isRespValueEmptyString(res) {
var resStr string
resStr, err := serializeOutput(res)
if err != nil {
return err
}
if err := writeOutput(resStr); err != nil {
return err
}
var resStr string
resStr, err = serializeOutput(res)
if err != nil {
return err
}
if err := writeOutput(resStr); err != nil {
return err
}
return nil
}
func isRespValueEmptyString(val resp.Value) bool {
return !val.IsNull() && (val.Type() == resp.SimpleString || val.Type() == resp.BulkString) && len(val.Bytes()) == 0
}
func randomKey(n int) string {
b := make([]byte, n)
nn, err := rand.Read(b)