Repository: qiniu/goc
Pull request #329 (2023-03-08 08:14:53)

Fix concurrent map iteration & write issue
The issue was introduced in `func (l *fileStore) Remove(addr string) error`
https://github.com/qiniu/goc/blob/master/pkg/cover/store.go#L107

when we set the memory server list back to file. 
the list `l.memoryStore.GetAll() -> services` passed into `func (l *fileStore) Set(services map[string][]string) error`
in [L175](https://github.com/qiniu/goc/blob/master/pkg/cover/store.go#L175) we sign the `services` directly to `l.memoryStore.servicesMap`, without copying it.

while in [L186](https://github.com/qiniu/goc/blob/master/pkg/cover/store.go#L186) we are still using this map to do the iteration without lock. (by right should use `memoryStore.mu`.

The issue will happen when there is another goroutine tries to remove the server from memoryStore. Map will clash.


qiniu-bot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/qiniu/goc/pull/329#" title="Author self-approved">Blaxon</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **memoryliu**
You can assign the PR to them by writing `/assign @memoryliu` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=qiniu%2Fgoc).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/qiniu/goc/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["memoryliu"]} -->
Blaxon: Solve issue: https://github.com/qiniu/goc/issues/324
codecov[bot]: # [Codecov](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) Report
> Merging [#329](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (383336e) into [master](https://codecov.io/gh/qiniu/goc/commit/5868a3e8136eb88174332b47021faa8ff7264203?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (5868a3e) will **increase** coverage by `0.04%`.
> The diff coverage is `100.00%`.

> :exclamation: Current head 383336e differs from pull request most recent head 041c06d. Consider uploading reports for the commit 041c06d to get more accurate results

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/qiniu/goc/pull/329/graphs/tree.svg?width=650&height=150&src=pr&token=7AHPDDLXQ3&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

```diff
@@            Coverage Diff             @@
##           master     #329      +/-   ##
==========================================
+ Coverage   70.76%   70.80%   +0.04%     
==========================================
  Files          34       34              
  Lines        2035     2038       +3     
==========================================
+ Hits         1440     1443       +3     
  Misses        482      482              
  Partials      113      113              
```

| Flag | Coverage Δ | |
|---|---|---|
| e2e-1.16.x | `?` | |
| e2e-1.17.x | `?` | |
| e2e-1.18.x | `?` | |
| e2e-1.19.x | `?` | |
| unittest-1.16.x | `70.70% <100.00%> (+0.04%)` | :arrow_up: |
| unittest-1.17.x | `70.80% <100.00%> (+0.14%)` | :arrow_up: |
| unittest-1.18.x | `70.80% <100.00%> (+0.14%)` | :arrow_up: |
| unittest-1.19.x | `70.70% <100.00%> (-0.06%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) | Coverage Δ | |
|---|---|---|
| [pkg/cover/instrument.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL2luc3RydW1lbnQuZ28=) | `20.83% <ø> (ø)` | |
| [pkg/cover/store.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL3N0b3JlLmdv) | `84.35% <100.00%> (+0.32%)` | :arrow_up: |

</details>
CarlJi: /assign @CarlJi 
codecov[bot]: ## [Codecov](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) Report
> Merging [#329](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (383336e) into [master](https://codecov.io/gh/qiniu/goc/commit/5868a3e8136eb88174332b47021faa8ff7264203?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (5868a3e) will **increase** coverage by `0.04%`.
> The diff coverage is `100.00%`.

> :exclamation: Current head 383336e differs from pull request most recent head b5f944c. Consider uploading reports for the commit b5f944c to get more accurate results

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/qiniu/goc/pull/329/graphs/tree.svg?width=650&height=150&src=pr&token=7AHPDDLXQ3&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

```diff
@@            Coverage Diff             @@
##           master     #329      +/-   ##
==========================================
+ Coverage   70.76%   70.80%   +0.04%     
==========================================
  Files          34       34              
  Lines        2035     2038       +3     
==========================================
+ Hits         1440     1443       +3     
  Misses        482      482              
  Partials      113      113              
```

| Flag | Coverage Δ | |
|---|---|---|
| e2e-1.16.x | `∅ <ø> (∅)` | |
| e2e-1.17.x | `∅ <ø> (∅)` | |
| e2e-1.18.x | `∅ <ø> (∅)` | |
| e2e-1.19.x | `∅ <ø> (∅)` | |
| unittest-1.16.x | `70.70% <100.00%> (+0.04%)` | :arrow_up: |
| unittest-1.17.x | `70.80% <100.00%> (+0.14%)` | :arrow_up: |
| unittest-1.18.x | `70.80% <100.00%> (+0.14%)` | :arrow_up: |
| unittest-1.19.x | `70.70% <100.00%> (-0.06%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) | Coverage Δ | |
|---|---|---|
| [pkg/cover/instrument.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL2luc3RydW1lbnQuZ28=) | `20.83% <ø> (ø)` | |
| [pkg/cover/store.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL3N0b3JlLmdv) | `84.35% <100.00%> (+0.32%)` | :arrow_up: |

</details>
qiniu-bot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/qiniu/goc/pull/329#" title="Author self-approved">Blaxon</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **carlji**
You can assign the PR to them by writing `/assign @carlji` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=qiniu%2Fgoc).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/qiniu/goc/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["carlji"]} -->
codecov[bot]: ## [Codecov](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) Report
> Merging [#329](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (1a6707e) into [master](https://codecov.io/gh/qiniu/goc/commit/5868a3e8136eb88174332b47021faa8ff7264203?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (5868a3e) will **decrease** coverage by `0.15%`.
> The diff coverage is `76.19%`.

> :exclamation: Current head 1a6707e differs from pull request most recent head b5f944c. Consider uploading reports for the commit b5f944c to get more accurate results

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/qiniu/goc/pull/329/graphs/tree.svg?width=650&height=150&src=pr&token=7AHPDDLXQ3&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

```diff
@@            Coverage Diff             @@
##           master     #329      +/-   ##
==========================================
- Coverage   70.76%   70.61%   -0.15%     
==========================================
  Files          34       34              
  Lines        2035     2042       +7     
==========================================
+ Hits         1440     1442       +2     
- Misses        482      487       +5     
  Partials      113      113              
```

| Flag | Coverage Δ | |
|---|---|---|
| e2e-1.16.x | `?` | |
| e2e-1.17.x | `?` | |
| e2e-1.18.x | `?` | |
| e2e-1.19.x | `?` | |
| unittest-1.16.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.17.x | `70.61% <76.19%> (-0.05%)` | :arrow_down: |
| unittest-1.18.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.19.x | `?` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) | Coverage Δ | |
|---|---|---|
| [pkg/cover/instrument.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL2luc3RydW1lbnQuZ28=) | `20.83% <ø> (ø)` | |
| [pkg/cover/store.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL3N0b3JlLmdv) | `81.45% <76.19%> (-2.58%)` | :arrow_down: |

... and [2 files with indirect coverage changes](https://codecov.io/gh/qiniu/goc/pull/329/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

</details>
codecov[bot]: ## [Codecov](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) Report
> Merging [#329](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (1a6707e) into [master](https://codecov.io/gh/qiniu/goc/commit/5868a3e8136eb88174332b47021faa8ff7264203?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (5868a3e) will **decrease** coverage by `0.15%`.
> The diff coverage is `76.19%`.

> :exclamation: Current head 1a6707e differs from pull request most recent head b5f944c. Consider uploading reports for the commit b5f944c to get more accurate results

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/qiniu/goc/pull/329/graphs/tree.svg?width=650&height=150&src=pr&token=7AHPDDLXQ3&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

```diff
@@            Coverage Diff             @@
##           master     #329      +/-   ##
==========================================
- Coverage   70.76%   70.61%   -0.15%     
==========================================
  Files          34       34              
  Lines        2035     2042       +7     
==========================================
+ Hits         1440     1442       +2     
- Misses        482      487       +5     
  Partials      113      113              
```

| Flag | Coverage Δ | |
|---|---|---|
| e2e-1.16.x | `?` | |
| e2e-1.17.x | `?` | |
| e2e-1.18.x | `?` | |
| e2e-1.19.x | `?` | |
| unittest-1.16.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.17.x | `70.61% <76.19%> (-0.05%)` | :arrow_down: |
| unittest-1.18.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.19.x | `70.51% <76.19%> (-0.25%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) | Coverage Δ | |
|---|---|---|
| [pkg/cover/instrument.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL2luc3RydW1lbnQuZ28=) | `20.83% <ø> (ø)` | |
| [pkg/cover/store.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL3N0b3JlLmdv) | `81.45% <76.19%> (-2.58%)` | :arrow_down: |

... and [2 files with indirect coverage changes](https://codecov.io/gh/qiniu/goc/pull/329/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

</details>
Blaxon: Hi @CarlJi , I just made a new commit 
1. to fix the fileStore.Remove data inconsistency issue,
2. and update the unit test to be verifiable.
Pls help check, Thanks!
codecov[bot]: ## [Codecov](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) Report
> Merging [#329](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (1a6707e) into [master](https://codecov.io/gh/qiniu/goc/commit/5868a3e8136eb88174332b47021faa8ff7264203?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (5868a3e) will **decrease** coverage by `0.15%`.
> The diff coverage is `76.19%`.

> :exclamation: Current head 1a6707e differs from pull request most recent head 267535a. Consider uploading reports for the commit 267535a to get more accurate results

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/qiniu/goc/pull/329/graphs/tree.svg?width=650&height=150&src=pr&token=7AHPDDLXQ3&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

```diff
@@            Coverage Diff             @@
##           master     #329      +/-   ##
==========================================
- Coverage   70.76%   70.61%   -0.15%     
==========================================
  Files          34       34              
  Lines        2035     2042       +7     
==========================================
+ Hits         1440     1442       +2     
- Misses        482      487       +5     
  Partials      113      113              
```

| Flag | Coverage Δ | |
|---|---|---|
| e2e-1.16.x | `∅ <ø> (∅)` | |
| e2e-1.17.x | `∅ <ø> (∅)` | |
| e2e-1.18.x | `∅ <ø> (∅)` | |
| e2e-1.19.x | `∅ <ø> (∅)` | |
| unittest-1.16.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.17.x | `70.61% <76.19%> (-0.05%)` | :arrow_down: |
| unittest-1.18.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.19.x | `70.51% <76.19%> (-0.25%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) | Coverage Δ | |
|---|---|---|
| [pkg/cover/instrument.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL2luc3RydW1lbnQuZ28=) | `20.83% <ø> (ø)` | |
| [pkg/cover/store.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL3N0b3JlLmdv) | `81.45% <76.19%> (-2.58%)` | :arrow_down: |

... and [2 files with indirect coverage changes](https://codecov.io/gh/qiniu/goc/pull/329/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

</details>
codecov[bot]: ## [Codecov](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) Report
> Merging [#329](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (1a6707e) into [master](https://codecov.io/gh/qiniu/goc/commit/5868a3e8136eb88174332b47021faa8ff7264203?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (5868a3e) will **decrease** coverage by `0.15%`.
> The diff coverage is `76.19%`.

> :exclamation: Current head 1a6707e differs from pull request most recent head 00142a6. Consider uploading reports for the commit 00142a6 to get more accurate results

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/qiniu/goc/pull/329/graphs/tree.svg?width=650&height=150&src=pr&token=7AHPDDLXQ3&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

```diff
@@            Coverage Diff             @@
##           master     #329      +/-   ##
==========================================
- Coverage   70.76%   70.61%   -0.15%     
==========================================
  Files          34       34              
  Lines        2035     2042       +7     
==========================================
+ Hits         1440     1442       +2     
- Misses        482      487       +5     
  Partials      113      113              
```

| Flag | Coverage Δ | |
|---|---|---|
| e2e-1.16.x | `∅ <ø> (∅)` | |
| e2e-1.17.x | `∅ <ø> (∅)` | |
| e2e-1.18.x | `∅ <ø> (∅)` | |
| e2e-1.19.x | `∅ <ø> (∅)` | |
| unittest-1.16.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.17.x | `70.61% <76.19%> (-0.05%)` | :arrow_down: |
| unittest-1.18.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.19.x | `70.51% <76.19%> (-0.25%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) | Coverage Δ | |
|---|---|---|
| [pkg/cover/instrument.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL2luc3RydW1lbnQuZ28=) | `20.83% <ø> (ø)` | |
| [pkg/cover/store.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL3N0b3JlLmdv) | `81.45% <76.19%> (-2.58%)` | :arrow_down: |

... and [2 files with indirect coverage changes](https://codecov.io/gh/qiniu/goc/pull/329/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

</details>
codecov[bot]: ## [Codecov](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) Report
> Merging [#329](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (b7fb044) into [master](https://codecov.io/gh/qiniu/goc/commit/5868a3e8136eb88174332b47021faa8ff7264203?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (5868a3e) will **decrease** coverage by `0.05%`.
> The diff coverage is `76.19%`.

> :exclamation: Current head b7fb044 differs from pull request most recent head 00142a6. Consider uploading reports for the commit 00142a6 to get more accurate results

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/qiniu/goc/pull/329/graphs/tree.svg?width=650&height=150&src=pr&token=7AHPDDLXQ3&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

```diff
@@            Coverage Diff             @@
##           master     #329      +/-   ##
==========================================
- Coverage   70.76%   70.71%   -0.05%     
==========================================
  Files          34       34              
  Lines        2035     2042       +7     
==========================================
+ Hits         1440     1444       +4     
- Misses        482      486       +4     
+ Partials      113      112       -1     
```

| Flag | Coverage Δ | |
|---|---|---|
| e2e-1.16.x | `?` | |
| e2e-1.17.x | `?` | |
| e2e-1.18.x | `?` | |
| e2e-1.19.x | `?` | |
| unittest-1.16.x | `70.71% <76.19%> (+0.05%)` | :arrow_up: |
| unittest-1.17.x | `70.61% <76.19%> (-0.05%)` | :arrow_down: |
| unittest-1.18.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.19.x | `70.61% <76.19%> (-0.15%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) | Coverage Δ | |
|---|---|---|
| [pkg/cover/instrument.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL2luc3RydW1lbnQuZ28=) | `20.83% <ø> (ø)` | |
| [pkg/cover/store.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL3N0b3JlLmdv) | `81.45% <76.19%> (-2.58%)` | :arrow_down: |

... and [1 file with indirect coverage changes](https://codecov.io/gh/qiniu/goc/pull/329/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

</details>
codecov[bot]: ## [Codecov](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) Report
> Merging [#329](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (b6cebb2) into [master](https://codecov.io/gh/qiniu/goc/commit/5868a3e8136eb88174332b47021faa8ff7264203?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (5868a3e) will **decrease** coverage by `0.25%`.
> The diff coverage is `76.19%`.

> :exclamation: Current head b6cebb2 differs from pull request most recent head 00142a6. Consider uploading reports for the commit 00142a6 to get more accurate results

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/qiniu/goc/pull/329/graphs/tree.svg?width=650&height=150&src=pr&token=7AHPDDLXQ3&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

```diff
@@            Coverage Diff             @@
##           master     #329      +/-   ##
==========================================
- Coverage   70.76%   70.51%   -0.25%     
==========================================
  Files          34       34              
  Lines        2035     2042       +7     
==========================================
  Hits         1440     1440              
- Misses        482      489       +7     
  Partials      113      113              
```

| Flag | Coverage Δ | |
|---|---|---|
| e2e-1.16.x | `?` | |
| e2e-1.17.x | `?` | |
| e2e-1.18.x | `?` | |
| e2e-1.19.x | `?` | |
| unittest-1.16.x | `?` | |
| unittest-1.17.x | `?` | |
| unittest-1.18.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.19.x | `?` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) | Coverage Δ | |
|---|---|---|
| [pkg/cover/instrument.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL2luc3RydW1lbnQuZ28=) | `20.83% <ø> (ø)` | |
| [pkg/cover/store.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL3N0b3JlLmdv) | `81.45% <76.19%> (-2.58%)` | :arrow_down: |

... and [1 file with indirect coverage changes](https://codecov.io/gh/qiniu/goc/pull/329/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

</details>
codecov[bot]: ## [Codecov](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) Report
> Merging [#329](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (b6cebb2) into [master](https://codecov.io/gh/qiniu/goc/commit/5868a3e8136eb88174332b47021faa8ff7264203?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) (5868a3e) will **decrease** coverage by `0.25%`.
> The diff coverage is `76.19%`.

> :exclamation: Current head b6cebb2 differs from pull request most recent head 00142a6. Consider uploading reports for the commit 00142a6 to get more accurate results

<details><summary>Additional details and impacted files</summary>


[![Impacted file tree graph](https://codecov.io/gh/qiniu/goc/pull/329/graphs/tree.svg?width=650&height=150&src=pr&token=7AHPDDLXQ3&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

```diff
@@            Coverage Diff             @@
##           master     #329      +/-   ##
==========================================
- Coverage   70.76%   70.51%   -0.25%     
==========================================
  Files          34       34              
  Lines        2035     2042       +7     
==========================================
  Hits         1440     1440              
- Misses        482      489       +7     
  Partials      113      113              
```

| Flag | Coverage Δ | |
|---|---|---|
| e2e-1.16.x | `?` | |
| e2e-1.17.x | `?` | |
| e2e-1.18.x | `?` | |
| e2e-1.19.x | `?` | |
| unittest-1.16.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.17.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.18.x | `70.51% <76.19%> (-0.15%)` | :arrow_down: |
| unittest-1.19.x | `70.51% <76.19%> (-0.25%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu) | Coverage Δ | |
|---|---|---|
| [pkg/cover/instrument.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL2luc3RydW1lbnQuZ28=) | `20.83% <ø> (ø)` | |
| [pkg/cover/store.go](https://codecov.io/gh/qiniu/goc/pull/329?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu#diff-cGtnL2NvdmVyL3N0b3JlLmdv) | `81.45% <76.19%> (-2.58%)` | :arrow_down: |

... and [1 file with indirect coverage changes](https://codecov.io/gh/qiniu/goc/pull/329/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=qiniu)

</details>

Patch:
diff --git a/pkg/cover/store.go b/pkg/cover/store.go
index 0929039..467021e 100644
--- a/pkg/cover/store.go
+++ b/pkg/cover/store.go
@@ -105,12 +105,15 @@ func (l *fileStore) GetAll() map[string][]string {
 
 // Remove the service from the memory store and the file store
 func (l *fileStore) Remove(addr string) error {
+	l.mu.Lock()
+	defer l.mu.Unlock()
+
 	err := l.memoryStore.Remove(addr)
 	if err != nil {
 		return err
 	}
 
-	return l.Set(l.memoryStore.GetAll())
+	return syncToFile(l.persistentFile, l.memoryStore.GetAll())
 }
 
 // Init cleanup all the registered service information
@@ -177,24 +180,7 @@ func (l *fileStore) Set(services map[string][]string) error {
 		return err
 	}
 
-	f, err := os.OpenFile(l.persistentFile, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0600)
-	if err != nil {
-		return err
-	}
-
-	s := ""
-	for name, addrs := range services {
-		for _, addr := range addrs {
-			s += fmt.Sprintf("%s&%s\n", name, addr)
-		}
-	}
-
-	_, err = f.WriteString(s)
-	if err != nil {
-		return err
-	}
-
-	return f.Sync()
+	return syncToFile(l.persistentFile, services)
 }
 
 func (l *fileStore) appendToFile(s ServiceUnderTest) error {
@@ -221,6 +207,27 @@ func split(r rune) bool {
 	return r == '&'
 }
 
+func syncToFile(persistentFile string, services map[string][]string) error {
+	f, err := os.OpenFile(persistentFile, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0600)
+	if err != nil {
+		return err
+	}
+
+	s := ""
+	for name, addrs := range services {
+		for _, addr := range addrs {
+			s += fmt.Sprintf("%s&%s\n", name, addr)
+		}
+	}
+
+	_, err = f.WriteString(s)
+	if err != nil {
+		return err
+	}
+
+	return f.Sync()
+}
+
 // memoryStore holds the registered services only into memory
 type memoryStore struct {
 	mu          sync.RWMutex
@@ -287,7 +294,11 @@ func (l *memoryStore) Set(services map[string][]string) error {
 	l.mu.Lock()
 	defer l.mu.Unlock()
 
-	l.servicesMap = services
+	newMap := make(map[string][]string)
+	for k, v := range services {
+		newMap[k] = append(make([]string, 0), v...)
+	}
+	l.servicesMap = newMap
 
 	return nil
 }
@@ -317,7 +328,7 @@ func (l *memoryStore) Remove(removeAddr string) error {
 	}
 
 	if !flag {
-		return fmt.Errorf("no service found")
+		return fmt.Errorf("no service found: %s", removeAddr)
 	}
 
 	return nil


Test patch:
diff --git a/pkg/cover/store_test.go b/pkg/cover/store_test.go
index a4898d8..e1a32ac 100644
--- a/pkg/cover/store_test.go
+++ b/pkg/cover/store_test.go
@@ -18,10 +18,10 @@ package cover
 
 import (
 	"fmt"
+	"github.com/stretchr/testify/assert"
 	"os"
+	"sync"
 	"testing"
-
-	"github.com/stretchr/testify/assert"
 )
 
 func TestLocalStore(t *testing.T) {
@@ -130,3 +130,32 @@ func TestFileStoreRemove(t *testing.T) {
 	err = store.Remove("http")
 	assert.Error(t, err, fmt.Errorf("no service found"))
 }
+
+// verify issue fix https://github.com/golang/go/issues/56552
+func TestConcurrentRemoval(t *testing.T) {
+	store, _ := NewFileStore("_svrs_address.txt")
+	_ = store.Init()
+
+	for i := 0; i < 100; i++ {
+		_ = store.Add(ServiceUnderTest{
+			Name:    fmt.Sprintf("test%d", i),
+			Address: fmt.Sprintf("http://127.0.0.1:890%d", i),
+		})
+	}
+
+	wg := sync.WaitGroup{}
+	for i := 0; i < 100; i++ {
+		j := i // for loop trap in golang, avoid goroutine uses the same value for i pointer
+		wg.Add(1)
+		go func() {
+			defer wg.Done()
+			err := store.Remove(fmt.Sprintf("http://127.0.0.1:890%d", j))
+			if err != nil {
+				t.Errorf("fileStore.Remove Error: %v", err)
+			}
+		}()
+	}
+	wg.Wait()
+
+	assert.Equal(t, 0, len(store.GetAll()))
+}