mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-10-05 18:03:21 +08:00
Refactor sessions and add locking to avoid concurrent requests to create
more instances
This commit is contained in:
@@ -14,12 +14,14 @@ func NewInstance(rw http.ResponseWriter, req *http.Request) {
|
||||
|
||||
s := services.GetSession(sessionId)
|
||||
|
||||
s.Lock()
|
||||
if len(s.Instances) >= 5 {
|
||||
rw.WriteHeader(http.StatusConflict)
|
||||
return
|
||||
}
|
||||
|
||||
i, err := services.NewInstance(s)
|
||||
s.Unlock()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
//TODO: Set a status error
|
||||
|
Reference in New Issue
Block a user