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

View File

@ -54,21 +54,20 @@ func setup(mc *mockServer, count int, points bool) (err error) {
return return
} }
func timeout_spatial_test(mc *mockServer) (err error) { func timeout_spatial_test(mc *mockServer) error {
err = setup(mc, 10000, true) err := setup(mc, 10000, true)
if err != nil { if err != nil {
return err 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{}{ Do("TIMEOUT", "0.000001", "SCAN", "mykey", "WHERE", "foo", -1, 2, "COUNT").Err("timeout"),
{"SCAN", "mykey", "WHERE", "foo", -1, 2, "COUNT"}, {"10000"}, Do("TIMEOUT", "0.000001", "INTERSECTS", "mykey", "WHERE", "foo", -1, 2, "COUNT", "BOUNDS", -90, -180, 90, 180).Err("timeout"),
{"INTERSECTS", "mykey", "WHERE", "foo", -1, 2, "COUNT", "BOUNDS", -90, -180, 90, 180}, {"10000"}, Do("TIMEOUT", "0.000001", "WITHIN", "mykey", "WHERE", "foo", -1, 2, "COUNT", "BOUNDS", -90, -180, 90, 180).Err("timeout"),
{"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"},
})
} }
func timeout_search_test(mc *mockServer) (err error) { func timeout_search_test(mc *mockServer) (err error) {