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

并行执行的代码BUG #146

Open
yangshii opened this issue Mar 5, 2021 · 1 comment
Open

并行执行的代码BUG #146

yangshii opened this issue Mar 5, 2021 · 1 comment

Comments

@yangshii
Copy link

yangshii commented Mar 5, 2021

并行执行部署时,协程未传参进去,导致所有协程执行的都是同一台机器。代码如下

func (d *Deploy) Parallel() {
if d.status == STATUS_FAILED {
return
}
d.status = STATUS_ING
status := STATUS_DONE
for _, srv := range d.srvs {
d.wg.Add(1)
go func() {
if d.status == STATUS_ING {
srv.Deploy()
if srv.Result().Status == STATUS_FAILED {
status = STATUS_FAILED
}
}
defer d.wg.Done()
}()
}
d.wg.Wait()
d.status = status
}

@hzylyq
Copy link

hzylyq commented Mar 31, 2021

for _, srv := range d.srvs {
		d.wg.Add(1)
		go func(srv *Server) {
			if d.status == STATUS_ING {
				srv.Deploy()
				if srv.Result().Status == STATUS_FAILED {
					status = STATUS_FAILED
				}
			}
			defer d.wg.Done()
		}(srv)
	}

应该要改成这样吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants