Fix race condition on server close

closes #61
This commit is contained in:
tidwall 2023-01-12 09:18:56 -07:00
parent bc9875b4b0
commit 8b671291b8
1 changed files with 16 additions and 15 deletions

View File

@ -335,7 +335,7 @@ func serve(s *Server) error {
s.mu.Lock()
defer s.mu.Unlock()
for c := range s.conns {
c.Close()
c.conn.Close()
}
s.conns = nil
}()
@ -602,9 +602,9 @@ func (w *Writer) WriteNull() {
// sub-responses to the client to complete the response.
// For example to write two strings:
//
// c.WriteArray(2)
// c.WriteBulkString("item 1")
// c.WriteBulkString("item 2")
// c.WriteArray(2)
// c.WriteBulkString("item 1")
// c.WriteBulkString("item 2")
func (w *Writer) WriteArray(count int) {
if w.err != nil {
return
@ -709,17 +709,18 @@ func (w *Writer) WriteRaw(data []byte) {
}
// WriteAny writes any type to client.
// nil -> null
// error -> error (adds "ERR " when first word is not uppercase)
// string -> bulk-string
// numbers -> bulk-string
// []byte -> bulk-string
// bool -> bulk-string ("0" or "1")
// slice -> array
// map -> array with key/value pairs
// SimpleString -> string
// SimpleInt -> integer
// everything-else -> bulk-string representation using fmt.Sprint()
//
// nil -> null
// error -> error (adds "ERR " when first word is not uppercase)
// string -> bulk-string
// numbers -> bulk-string
// []byte -> bulk-string
// bool -> bulk-string ("0" or "1")
// slice -> array
// map -> array with key/value pairs
// SimpleString -> string
// SimpleInt -> integer
// everything-else -> bulk-string representation using fmt.Sprint()
func (w *Writer) WriteAny(v interface{}) {
if w.err != nil {
return