Fix hang on empty RESP response

This commit is contained in:
tidwall 2022-09-24 07:22:39 -07:00
parent 5460998086
commit e6cced4c4a
2 changed files with 18 additions and 25 deletions

View File

@ -949,7 +949,7 @@ func (s *Server) handleInputCommand(client *Client, msg *Message) error {
}
}
res = NOMessage
err = writeErr("timeout")
err = errTimeout
}
}()
}
@ -977,23 +977,17 @@ func (s *Server) handleInputCommand(client *Client, msg *Message) error {
return err
}
}
if false || !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)

View File

@ -54,21 +54,20 @@ func setup(mc *mockServer, count int, points bool) (err error) {
return
}
func timeout_spatial_test(mc *mockServer) (err error) {
err = setup(mc, 10000, true)
func timeout_spatial_test(mc *mockServer) error {
err := setup(mc, 10000, true)
if err != nil {
return err
}
return mc.DoBatch(
Do("SCAN", "mykey", "WHERE", "foo", -1, 2, "COUNT").Str("10000"),
Do("INTERSECTS", "mykey", "WHERE", "foo", -1, 2, "COUNT", "BOUNDS", -90, -180, 90, 180).Str("10000"),
Do("WITHIN", "mykey", "WHERE", "foo", -1, 2, "COUNT", "BOUNDS", -90, -180, 90, 180).Str("10000"),
return mc.DoBatch([][]interface{}{
{"SCAN", "mykey", "WHERE", "foo", -1, 2, "COUNT"}, {"10000"},
{"INTERSECTS", "mykey", "WHERE", "foo", -1, 2, "COUNT", "BOUNDS", -90, -180, 90, 180}, {"10000"},
{"WITHIN", "mykey", "WHERE", "foo", -1, 2, "COUNT", "BOUNDS", -90, -180, 90, 180}, {"10000"},
{"TIMEOUT", "0.000001", "SCAN", "mykey", "WHERE", "foo", -1, 2, "COUNT"}, {"ERR timeout"},
{"TIMEOUT", "0.000001", "INTERSECTS", "mykey", "WHERE", "foo", -1, 2, "COUNT", "BOUNDS", -90, -180, 90, 180}, {"ERR timeout"},
{"TIMEOUT", "0.000001", "WITHIN", "mykey", "WHERE", "foo", -1, 2, "COUNT", "BOUNDS", -90, -180, 90, 180}, {"ERR timeout"},
})
Do("TIMEOUT", "0.000001", "SCAN", "mykey", "WHERE", "foo", -1, 2, "COUNT").Err("timeout"),
Do("TIMEOUT", "0.000001", "INTERSECTS", "mykey", "WHERE", "foo", -1, 2, "COUNT", "BOUNDS", -90, -180, 90, 180).Err("timeout"),
Do("TIMEOUT", "0.000001", "WITHIN", "mykey", "WHERE", "foo", -1, 2, "COUNT", "BOUNDS", -90, -180, 90, 180).Err("timeout"),
)
}
func timeout_search_test(mc *mockServer) (err error) {