gorse-io / gorse-io/gorse

Data race: worker.Sync() and worker.Recommend()

Open
#606 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
9.8k
Forks
912
Avg merge
2h 35m
Merged PRs (30d)
9

Description

**Gorse version**
Version: unknown-version
API version: v0.2.7
Go version: go1.19.3
Git commit: 762f21f3154f35877fe376ba435c11e7eaaf5edc

**Describe the bug**
A data race occurs when the worker configuration is updated.
[Sync()](https://github.com/gorse-io/gorse/blob/762f21f3154f35877fe376ba435c11e7eaaf5edc/worker/worker.go#L381) write [w.Config](https://github.com/gorse-io/gorse/blob/762f21f3154f35877fe376ba435c11e7eaaf5edc/worker/worker.go#L155), and [Recommend()](https://github.com/gorse-io/gorse/blob/762f21f3154f35877fe376ba435c11e7eaaf5edc/worker/worker.go#L404) read.

Perhaps it is better to sync the configuration only between reranking cycles? Because the sync operation is much faster than the calculation of recommendations, as well as changing the configuration parameters during the ranking process can lead to incorrect result.

**To Reproduce**
[Test](https://github.com/ingosus/gorse/blob/config_update_race/worker/worker_test.go#L685)
go test -v -race github.com/zhenghaoz/gorse/worker -run TestWorker_SyncRecommend

**Expected behavior**
no data race

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.