Skip to content

Commit

Permalink
Fix close session bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xetorthio committed Aug 10, 2017
1 parent 7c89054 commit 79181b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pwd/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ func (p *pwd) InstanceDelete(session *types.Session, instance *types.Instance) e
return err
}

p.event.Emit(event.INSTANCE_DELETE, session.Id, instance.Name)

if err := p.storage.InstanceDelete(session.Id, instance.Name); err != nil {
return err
}

p.event.Emit(event.INSTANCE_DELETE, session.Id, instance.Name)

p.setGauges()

return nil
Expand Down
22 changes: 16 additions & 6 deletions pwd/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/play-with-docker/play-with-docker/docker"
"github.com/play-with-docker/play-with-docker/event"
"github.com/play-with-docker/play-with-docker/pwd/types"
"github.com/play-with-docker/play-with-docker/storage"
)

var preparedSessions = map[string]bool{}
Expand Down Expand Up @@ -72,7 +73,7 @@ func (p *pwd) SessionNew(duration time.Duration, stack, stackName, imageName str
}

if err := dockerClient.CreateNetwork(s.Id); err != nil {
log.Println("ERROR NETWORKING")
log.Println("ERROR NETWORKING", err)
return nil, err
}
log.Printf("Network [%s] created for session [%s]\n", s.Id, s.Id)
Expand All @@ -99,8 +100,17 @@ func (p *pwd) SessionNew(duration time.Duration, stack, stackName, imageName str
func (p *pwd) SessionClose(s *types.Session) error {
defer observeAction("SessionClose", time.Now())

s.Lock()
defer s.Unlock()
updatedSession, err := p.storage.SessionGet(s.Id)
if err != nil {
if storage.NotFound(err) {
log.Printf("Session with id [%s] was not found in storage.\n", s.Id)
return err
} else {
log.Printf("Couldn't close session. Got: %s\n", err)
return err
}
}
s = updatedSession

log.Printf("Starting clean up of session [%s]\n", s.Id)
for _, i := range s.Instances {
Expand All @@ -113,19 +123,19 @@ func (p *pwd) SessionClose(s *types.Session) error {
// Disconnect PWD daemon from the network
if err := p.docker(s.Id).DisconnectNetwork(config.L2ContainerName, s.Id); err != nil {
if !strings.Contains(err.Error(), "is not connected to the network") {
log.Println("ERROR NETWORKING")
log.Println("ERROR NETWORKING", err)
return err
}
}
log.Printf("Disconnected pwd from network [%s]\n", s.Id)
log.Printf("Disconnected l2 from network [%s]\n", s.Id)
if err := p.docker(s.Id).DeleteNetwork(s.Id); err != nil {
if !strings.Contains(err.Error(), "not found") {
log.Println(err)
return err
}
}

err := p.storage.SessionDelete(s.Id)
err = p.storage.SessionDelete(s.Id)
if err != nil {
return err
}
Expand Down

0 comments on commit 79181b2

Please sign in to comment.