Fix hang on empty response

This commit is contained in:
tidwall 2022-09-24 07:24:04 -07:00
parent a824d58419
commit 2b6ab4368a

View File

@ -947,7 +947,7 @@ func (s *Server) handleInputCommand(client *Client, msg *Message) error {
} }
} }
res = NOMessage res = NOMessage
err = writeErr("timeout") err = errTimeout
} }
}() }()
} }
@ -975,23 +975,17 @@ func (s *Server) handleInputCommand(client *Client, msg *Message) error {
return err return err
} }
} }
if !isRespValueEmptyString(res) {
var resStr string var resStr string
resStr, err := serializeOutput(res) resStr, err = serializeOutput(res)
if err != nil { if err != nil {
return err return err
} }
if err := writeOutput(resStr); err != nil { if err := writeOutput(resStr); err != nil {
return err return err
} }
}
return nil 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 { func randomKey(n int) string {
b := make([]byte, n) b := make([]byte, n)
nn, err := rand.Read(b) nn, err := rand.Read(b)