personium / personium-core

Core module of Personium
https://personium.io
Apache License 2.0
88 stars 16 forks source link

Memcached Changes the behavior at update failure. #35

Closed SawamiWataru closed 6 years ago

SawamiWataru commented 7 years ago

Personium source code

MemcachedClient#put()

if (this.spyClient.replace(key, expiresIn, object).get()) {
    return true;
} else {
    return this.spyClient.add(key, expiresIn, object).get();
}

If false is returned, an error occurs.

Problem

Problems may occur at the time of simultaneous access.

Assume that API to be executed concurrently is [API-1] [API-2]. A phenomenon occurs when the following processing order is reached.

  1. [API-1] Call replace.
  2. [API-1] False is returned because there is no information in memcache.
  3. [API-2] Call replace.
  4. [API-2] False is returned because there is no information in memcache.
  5. [API-1] Call add.
  6. [API-1] Write information to memcache and return true.
  7. [API-2] Call add.
  8. [API-2] False is returned because there is information in memcache.

As a result, it is not an abnormal state, but it is an error.

SawamiWataru commented 7 years ago

Solution

If add fails, calling replace again.

SawamiWataru commented 6 years ago

Solved in v1.5.4.