Bug 1897294
| Summary: | Race condition in OrderedDict.popitem() | ||
|---|---|---|---|
| Product: | Red Hat Enterprise Linux 8 | Reporter: | Radomir Dopieralski <rdopiera> |
| Component: | python3 | Assignee: | Python Maintainers <python-maint> |
| Status: | CLOSED WONTFIX | QA Contact: | RHEL CS Apps Subsystem QE <rhel-cs-apps-subsystem-qe> |
| Severity: | unspecified | Docs Contact: | |
| Priority: | unspecified | ||
| Version: | 8.2 | CC: | tkajinam, vstinner |
| Target Milestone: | rc | Flags: | pm-rhel:
mirror+
|
| Target Release: | 8.0 | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | If docs needed, set a value | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2020-11-17 14:28:35 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
| Bug Depends On: | |||
| Bug Blocks: | 1896614 | ||
|
Description
Radomir Dopieralski
2020-11-12 17:38:54 UTC
According to the customer ticket, Python 2.7 is being used. Before Python 3.5, you are correct that the OrderedDict.popitem() method was not thread safe.
To support Python 2.7, you must protect all (read/write) accesses to the OrderedDict by a lock in your application (Horizon).
Or you should attempt to upgrade to Python 3.5 or newer which is safe. RHEL8 provides Python 3.6 which is safe, for example.
Python collections.OrderedDict type cannot be modified to use a lock, it would likely introduce *new* deadlocks in multithreaded applications (like Horizon) which would not be prepared for that.
--
Before Python 3.5, collections.OrderedDict was implemented in pure Python. It was no thread safe since the type does not use a lock internally. Usually, Python builtin types are not thread safe by design, but only because they are implemented in C which makes most methods atomic thanks to the GIL. In practice, it's more complicated than that. If a C method calls arbitrary code, it can release the GIL and so is no longer thread safe.
Since Python 3.5, Python now also provides _collections.OrderedDict type which is implemented in C. collections/__init__.py:
---
class OrderedDict(dict):
# Python implementation
...
try:
from _collections import OrderedDict
# C implementation overrides the Python implementation
except ImportError:
# Leave the pure Python version in place.
pass
---
The C implementation of the _collections.OrderedDict.popitem() method is protected by the GIL and so looks to be thread-safe.
@Victor You are correct and the deployment has python2.7 used, because it is the deployment with RHOSP13 on RHEL7. Unfortunately I'm afraid that we can't update the python to 3.5. There are no plans to update the base python for RHOSP13 so far, I don't think that update can happen regarding the support phase of RHOSP13 and possible huge effect that update can cause. So we should add some locking mechanism to Horizon, to downstream RHOSP13. (And the two stable branches in upsteam, stable/rocky and stable/train, which support Python2, ideally) We don't expect the same issue with RHOSP16.y which depends on python3.6 and RHEL8, according to your information. I think that in OSP13 we can simply work around that issue by catching the unexpected exception. I'm closing this, since we are not going to be fixing Python. |