Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Make InfluxDBClusterClient thread-safe#265

Merged
aviau merged 1 commit into
influxdata:masterfrom
PierreF:cluster-client-threadsafe
Nov 18, 2015
Merged

Make InfluxDBClusterClient thread-safe#265
aviau merged 1 commit into
influxdata:masterfrom
PierreF:cluster-client-threadsafe

Conversation

@PierreF
Copy link
Copy Markdown
Contributor

@PierreF PierreF commented Nov 17, 2015

We had an issue with InfluxDBClusterClient an multi-threading : it is not thread safe :(

The thread-safe issues I spotted:

  • random.shuffle : calling random.shuffle on the same list from multiple thread could corrupt that list
  • removing item from list: two thread may try to remove the same entry from the list
  • update host on ONE client: one thread may update client host before another one called orig_func. Therefor when exception occur or no, the variable "h" may no be the real server used.

For first 2 issues, a simple lock around the affected code solve the issue.

For the last issue, it a bit trickier... I ended with a getter (_get_host() and _get_baseurl()), so InfluxDBClusterClient could override them with code that use a thread local variable.

I've also added properties to avoid changing every access to _host or _baseurl, but since those variables should not be used outside influxdb-python code, we could avoid them and directly use the getter.

@aviau
Copy link
Copy Markdown
Collaborator

aviau commented Nov 18, 2015

thank you for your work!

aviau added a commit that referenced this pull request Nov 18, 2015
Make InfluxDBClusterClient thread-safe (Thanks @PierreF !)
@aviau aviau merged commit 996d009 into influxdata:master Nov 18, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants