Lock when creating new sessions as access to session map cannot happen

concurrently
This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-06-12 12:59:34 -03:00
parent e09ac22579
commit 37c16d0d98
2 changed files with 5 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package pwd
import (
"sync"
"time"
"github.com/play-with-docker/play-with-docker/docker"
@@ -23,6 +24,7 @@ var (
)
var sessions map[string]*Session
var sessionsMutex sync.Mutex
func init() {
prometheus.MustRegister(sessionsGauge)

View File

@@ -52,6 +52,9 @@ type Session struct {
}
func (p *pwd) SessionNew(duration time.Duration, stack, stackName string) (*Session, error) {
sessionsMutex.Lock()
defer sessionsMutex.Unlock()
s := &Session{}
s.Id = uuid.NewV4().String()
s.Instances = map[string]*Instance{}