From e573d66b91c6287b5f3af14ef5ec9efecd428289 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 13 Jul 2016 12:00:07 -0700 Subject: [PATCH 1/3] remove unstable acknowledgements --- drone/build_start.go | 4 ++-- drone/server.go | 46 -------------------------------------------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/drone/build_start.go b/drone/build_start.go index 7a871f0c..00d18aa6 100644 --- a/drone/build_start.go +++ b/drone/build_start.go @@ -43,9 +43,9 @@ func buildStart(c *cli.Context) (err error) { var build *model.Build if c.Bool("fork") { - build, err = client.BuildStart(owner, name, number) - } else { build, err = client.BuildFork(owner, name, number) + } else { + build, err = client.BuildStart(owner, name, number) } if err != nil { return err diff --git a/drone/server.go b/drone/server.go index 2e6468b6..a1b9fb06 100644 --- a/drone/server.go +++ b/drone/server.go @@ -1,9 +1,7 @@ package main import ( - "fmt" "net/http" - "os" "time" "github.com/drone/drone/router" @@ -263,30 +261,11 @@ var serverCmd = cli.Command{ Name: "stash-skip-verify", Usage: "stash skip ssl verification", }, - // - // remove these eventually - // - - cli.BoolFlag{ - Name: "agreement.ack", - EnvVar: "I_UNDERSTAND_I_AM_USING_AN_UNSTABLE_VERSION", - Usage: "agree to terms of use.", - }, - cli.BoolFlag{ - Name: "agreement.fix", - EnvVar: "I_AGREE_TO_FIX_BUGS_AND_NOT_FILE_BUGS", - Usage: "agree to terms of use.", - }, }, } func server(c *cli.Context) error { - if c.Bool("agreement.ack") == false || c.Bool("agreement.fix") == false { - fmt.Println(agreement) - os.Exit(1) - } - // debug level if requested by user if c.Bool("debug") { logrus.SetLevel(logrus.DebugLevel) @@ -324,28 +303,3 @@ func server(c *cli.Context) error { handler, ) } - -var agreement = ` ---- - - -You are attempting to use the unstable channel. This build is experimental and -has known bugs and compatibility issues. It is not intended for general use. - -Please consider using the latest stable release instead: - - drone/drone:0.4.2 - -If you are attempting to build from source please use the latest stable tag: - - v0.4.2 - -If you are interested in testing this experimental build AND assisting with -development you may proceed by setting the following environment: - - I_UNDERSTAND_I_AM_USING_AN_UNSTABLE_VERSION=true - I_AGREE_TO_FIX_BUGS_AND_NOT_FILE_BUGS=true - - ---- -` From c27a5dd0b4ce0ae608f156a50134dfb316a44f47 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 13 Jul 2016 14:25:40 -0700 Subject: [PATCH 2/3] modifying cancel logic --- server/build.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/build.go b/server/build.go index 91f7df8d..87beacf4 100644 --- a/server/build.go +++ b/server/build.go @@ -135,6 +135,19 @@ func DeleteBuild(c *gin.Context) { return } + if job.Status != model.StatusRunning { + c.String(400, "Cannot cancel a non-running build") + return + } + + job.Status = model.StatusKilled + job.Finished = time.Now().Unix() + if job.Started == 0 { + job.Started = job.Finished + } + job.ExitCode = 137 + store.UpdateBuildJob(c, build, job) + bus.Publish(c, bus.NewEvent(bus.Cancelled, repo, build, job)) c.String(204, "") } From 71de0d94085eb92fa80d9df0e7dc3afdf7382f7d Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Wed, 13 Jul 2016 17:33:28 -0700 Subject: [PATCH 3/3] hacky fixed for race conditions on cancel --- build/pipeline.go | 53 ++++++++++++++++++++++++++++++++++++++++++----- server/build.go | 1 + 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/build/pipeline.go b/build/pipeline.go index 5f7e366a..ddeca757 100644 --- a/build/pipeline.go +++ b/build/pipeline.go @@ -3,6 +3,7 @@ package build import ( "bufio" "strconv" + "sync" "time" "github.com/Sirupsen/logrus" @@ -20,6 +21,7 @@ type Pipeline struct { conf *yaml.Config head *element tail *element + wait sync.WaitGroup pipe chan (*Line) next chan (error) done chan (error) @@ -87,6 +89,11 @@ func (p *Pipeline) Tail() *yaml.Container { // Stop stops the pipeline. func (p *Pipeline) Stop() { go func() { + defer func() { + if r := recover(); r != nil { + logrus.Errorln("recover stopping the pipeline", r) + } + }() p.done <- ErrTerm }() } @@ -98,9 +105,11 @@ func (p *Pipeline) Setup() error { // Teardown removes the pipeline environment. func (p *Pipeline) Teardown() { + for _, id := range p.containers { p.engine.ContainerRemove(id) } + close(p.next) close(p.done) @@ -114,10 +123,32 @@ func (p *Pipeline) Teardown() { func (p *Pipeline) step() { if p.head == p.tail { go func() { + defer func() { + if r := recover(); r != nil { + logrus.Errorln("recover executing step function", r) + } + }() + + // stop all containers + for _, id := range p.containers { + p.engine.ContainerStop(id) + } + + // wait for all logs to terminate + // p.wait.Done() // this is for the ambassador + p.wait.Wait() + + // signal completion p.done <- nil }() } else { go func() { + defer func() { + if r := recover(); r != nil { + logrus.Errorln("recover executing step to head function", r) + } + }() + p.head = p.head.next p.next <- nil }() @@ -137,17 +168,23 @@ func (p *Pipeline) close(err error) { } func (p *Pipeline) exec(c *yaml.Container) error { + name, err := p.engine.ContainerStart(c) if err != nil { return err } p.containers = append(p.containers, name) + logrus.Debugf("wait.add(1) for %s logs", name) + p.wait.Add(1) go func() { defer func() { if r := recover(); r != nil { logrus.Errorln("recover writing build output", r) } + + logrus.Debugf("wait.done() for %s logs", name) + p.wait.Done() }() rc, rerr := p.engine.ContainerLogs(name) @@ -179,17 +216,16 @@ func (p *Pipeline) exec(c *yaml.Container) error { if err != nil { return err } - if state.OOMKilled { - return &OomError{c.Name} - } else if state.ExitCode != 0 { - return &ExitError{c.Name, state.ExitCode} - } + logrus.Debugf("wait.add(1) for %s exit code", name) + p.wait.Add(1) go func() { defer func() { if r := recover(); r != nil { logrus.Errorln("recover writing exit code to output", r) } + p.wait.Done() + logrus.Debugf("wait.done() for %s exit code", name) }() p.pipe <- &Line{ @@ -198,5 +234,12 @@ func (p *Pipeline) exec(c *yaml.Container) error { Out: strconv.Itoa(state.ExitCode), } }() + + if state.OOMKilled { + return &OomError{c.Name} + } else if state.ExitCode != 0 { + return &ExitError{c.Name, state.ExitCode} + } + return nil } diff --git a/server/build.go b/server/build.go index 87beacf4..28571782 100644 --- a/server/build.go +++ b/server/build.go @@ -255,6 +255,7 @@ func PostBuild(c *gin.Context) { build.Finished = 0 build.Enqueued = time.Now().UTC().Unix() for _, job := range jobs { + job.Error = "" job.Status = model.StatusPending job.Started = 0 job.Finished = 0