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

server: guard sessions access in mutex #713

Merged
merged 1 commit into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ func (s *SessionManager) NewSession(conn *mysql.Conn) {
s.mu.Unlock()
}

func (s *SessionManager) session(conn *mysql.Conn) sql.Session {
s.mu.Lock()
defer s.mu.Unlock()
return s.sessions[conn.ConnectionID]
}

// NewContext creates a new context for the session at the given conn.
func (s *SessionManager) NewContext(conn *mysql.Conn) *sql.Context {
return s.NewContextWithQuery(conn, "")
Expand Down
7 changes: 3 additions & 4 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,11 @@ func (h *Handler) ComQuery(
// ComQuery callback if the result does not contain any fields,
// or after the last ComQuery call completes.
func (h *Handler) WarningCount(c *mysql.Conn) uint16 {
sess, ok := h.sm.sessions[c.ConnectionID]
if !ok {
return 0
if sess := h.sm.session(c); sess != nil {
return sess.WarningCount()
}

return sess.WarningCount()
return 0
}

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