mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
Fix data race in clientapi/routing/register.go (#787)
This commit is contained in:
parent
bf5efbc31f
commit
0ed2dd0b15
1 changed files with 12 additions and 3 deletions
|
@ -29,6 +29,7 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/common/config"
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
|
@ -70,12 +71,17 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// sessionsDict keeps track of completed auth stages for each session.
|
// sessionsDict keeps track of completed auth stages for each session.
|
||||||
|
// It shouldn't be passed by value because it contains a mutex.
|
||||||
type sessionsDict struct {
|
type sessionsDict struct {
|
||||||
|
sync.Mutex
|
||||||
sessions map[string][]authtypes.LoginType
|
sessions map[string][]authtypes.LoginType
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCompletedStages returns the completed stages for a session.
|
// GetCompletedStages returns the completed stages for a session.
|
||||||
func (d sessionsDict) GetCompletedStages(sessionID string) []authtypes.LoginType {
|
func (d *sessionsDict) GetCompletedStages(sessionID string) []authtypes.LoginType {
|
||||||
|
d.Lock()
|
||||||
|
defer d.Unlock()
|
||||||
|
|
||||||
if completedStages, ok := d.sessions[sessionID]; ok {
|
if completedStages, ok := d.sessions[sessionID]; ok {
|
||||||
return completedStages
|
return completedStages
|
||||||
}
|
}
|
||||||
|
@ -91,12 +97,15 @@ func newSessionsDict() *sessionsDict {
|
||||||
|
|
||||||
// AddCompletedSessionStage records that a session has completed an auth stage.
|
// AddCompletedSessionStage records that a session has completed an auth stage.
|
||||||
func AddCompletedSessionStage(sessionID string, stage authtypes.LoginType) {
|
func AddCompletedSessionStage(sessionID string, stage authtypes.LoginType) {
|
||||||
for _, completedStage := range sessions.GetCompletedStages(sessionID) {
|
sessions.Lock()
|
||||||
|
defer sessions.Unlock()
|
||||||
|
|
||||||
|
for _, completedStage := range sessions.sessions[sessionID] {
|
||||||
if completedStage == stage {
|
if completedStage == stage {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sessions.sessions[sessionID] = append(sessions.GetCompletedStages(sessionID), stage)
|
sessions.sessions[sessionID] = append(sessions.sessions[sessionID], stage)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
Loading…
Reference in a new issue