caicloud / nirvana

Golang Restful API Framework for Productivity
https://caicloud.github.io/nirvana/
Apache License 2.0
520 stars 105 forks source link

fix(config): add lock in Set function to avoid concurrent map writes when we run several servers at once #406

Closed iawia002 closed 4 years ago

iawia002 commented 4 years ago

What this PR does / why we need it:

In the current design, if we start more than one server at the same time, eg:

cmd := config.NewNamedNirvanaCommand("server1", &config.Option{Port: 7070})
cmd2 := config.NewNamedNirvanaCommand("server2", &config.Option{Port: 7071})

go cmd.Execute(echo)
go cmd2.Execute(echo)

<-stopCh

This has the probability of causing the concurrent map writes error in the Set method

Which issue(s) this PR is related to (optional, link to 3rd issue(s)):

Fixes #

Reference to #

Special notes for your reviewer:

/cc @xpofei

Release note:

NONE
iawia002 commented 4 years ago

/cherrypick release-0.3

caicloud-bot commented 4 years ago

@iawia002: once the present PR merges, I will cherry-pick it on top of release-0.3 in a new PR and assign it to you.

In response to [this](https://github.com/caicloud/nirvana/pull/406#issuecomment-736935422): >/cherrypick release-0.3 Instructions for interacting with me using PR comments are available [here](https://github.com/caicloud/engineering/blob/master/docs/caicloud_bot.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
xpofei commented 4 years ago

/lgtm

iawia002 commented 4 years ago

/approve

caicloud-bot commented 4 years ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: iawia002, xpofei

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/caicloud/nirvana/blob/master/OWNERS)~~ [iawia002] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
caicloud-bot commented 4 years ago

@iawia002: new pull request created: #407

In response to [this](https://github.com/caicloud/nirvana/pull/406#issuecomment-736935422): >/cherrypick release-0.3 Instructions for interacting with me using PR comments are available [here](https://github.com/caicloud/engineering/blob/master/docs/caicloud_bot.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.