Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a oom bug #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (bfs *buffers) set(key string, value *buffer) {
func (bfs *buffers) remove(key string) {
bfs.Lock()
defer bfs.Unlock()
close(bfs.bufferMap[key].in)
delete(bfs.bufferMap, key)
}

Expand Down
10 changes: 6 additions & 4 deletions examples/advanced/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (d *downloadStep) Cancel() error {
return nil
}

func readPipeline(pipe *pipeline.Pipeline) {
func readPipeline(ctx context.Context, pipe *pipeline.Pipeline) {
out, err := pipe.Out()
if err != nil {
return
Expand All @@ -92,6 +92,8 @@ func readPipeline(pipe *pipeline.Pipeline) {
fmt.Println(line)
case p := <-progress:
fmt.Println("percent done: ", p)
case <-ctx.Done():
return //结束当前的函数,以防止goroutine泄漏
}
}
}
Expand Down Expand Up @@ -124,16 +126,16 @@ func main() {

// add all stages
workflow.AddStage(stage, concurrentStage, concurrentErrStage)

ctx, cancelFunc := context.WithCancel(context.Background())
// start a routine to read out and progress
go readPipeline(workflow)
go readPipeline(ctx, workflow)

// execute pipeline
result := workflow.Run()
if result.Error != nil {
fmt.Println(result.Error)
}

cancelFunc() // 停止读取流水线输出的goroutine
// one would persist the time taken duration to use as progress scale for the next workflow build
fmt.Println("timeTaken:", workflow.GetDuration())

Expand Down