globocom / globocom/GloboNetworkAPI

Concurrency problem with healthcheck

Open
#151 1 comment 0 reactions 0 assignees View on GitHub
hacktoberfest
Dominant language
Python
Stars
88
Forks
71
Avg merge
1d 10h
Merged PRs (30d)
4

Description

Class below is called when creating a new pool. When two requests are trying to create a healthcheck with the same identifier, it can be duplicated on the DB, causing next requests with same data to fail, as it would return two objects on get().
Need to change code to avoid this from happening. Use lock?

networkapi.healthcheckexpect.models:
class Healthcheck(BaseModel):
def get_create_healthcheck(self, healthcheck):
try:
hc = Healthcheck.objects.get(**healthcheck)
except ObjectDoesNotExist:
hc = Healthcheck(**healthcheck)
hc.save()

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.