Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 6281186

Browse files
authored
server: guard sessions access in mutex (#713)
server: guard sessions access in mutex
2 parents b8dcf43 + c55fcbc commit 6281186

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

server/context.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ func (s *SessionManager) NewSession(conn *mysql.Conn) {
6464
s.mu.Unlock()
6565
}
6666

67+
func (s *SessionManager) session(conn *mysql.Conn) sql.Session {
68+
s.mu.Lock()
69+
defer s.mu.Unlock()
70+
return s.sessions[conn.ConnectionID]
71+
}
72+
6773
// NewContext creates a new context for the session at the given conn.
6874
func (s *SessionManager) NewContext(conn *mysql.Conn) *sql.Context {
6975
return s.NewContextWithQuery(conn, "")

server/handler.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,11 @@ func (h *Handler) ComQuery(
150150
// ComQuery callback if the result does not contain any fields,
151151
// or after the last ComQuery call completes.
152152
func (h *Handler) WarningCount(c *mysql.Conn) uint16 {
153-
sess, ok := h.sm.sessions[c.ConnectionID]
154-
if !ok {
155-
return 0
153+
if sess := h.sm.session(c); sess != nil {
154+
return sess.WarningCount()
156155
}
157156

158-
return sess.WarningCount()
157+
return 0
159158
}
160159

161160
func (h *Handler) handleKill(conn *mysql.Conn, query string) (bool, error) {

0 commit comments

Comments
 (0)