Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken identity cache (shelve / bdb) when multiple parallel logins happen: _dbm.error: cannot add item to database #946

Open
spaceone opened this issue Jan 3, 2024 · 0 comments
Labels

Comments

@spaceone
Copy link
Contributor

spaceone commented Jan 3, 2024

We have a web service running with multiprocessing and therefore cannot have a in-memory identity cache but must share them between the instances.
The documentation of the used shelve module for the identity cache says:

The shelve module does not support concurrent read/write access to shelved objects. (Multiple simultaneous read accesses are safe.) When a program has a shelf open for writing, no other program should have it open for reading or writing. Unix file locking can be used to solve this, but this differs across Unix versions and requires knowledge about the database implementation used.

But pysaml2 doesn't seem to have some locking around write operations.

The exception we receive from customer systems then are:

    response = self.sp.parse_authn_request_response(message, binding, self.outstanding_queries)
  File "/usr/lib/python3/dist-packages/saml2/client_base.py", line 717, in parse_authn_request_response
    self.users.add_information_about_person(resp.session_info())
  File "/usr/lib/python3/dist-packages/saml2/population.py", line 27, in add_information_about_person
    session_info["not_on_or_after"])
  File "/usr/lib/python3/dist-packages/saml2/cache.py", line 129, in set
    self._db[cni] = data
  File "/usr/lib/python3.7/shelve.py", line 125, in __setitem__
    self.dict[key.encode(self.keyencoding)] = f.getvalue()
_dbm.error: cannot add item to database

The database is then in corrupt state:

# db_verify saml-18202.bdb.db
db_verify: BDB0540 Page 1: invalid next_pgno 8780
db_verify: BDB0540 Page 2: invalid next_pgno 6952
db_verify: saml-18202.bdb.db: BDB0090 DB_VERIFY_BAD: Database verification failed
BDB5105 Verification of saml-18202.bdb.db failed.

related issues: #373 (maybe #741, #740).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants