apache / incubator-ponymail-foal

Apache Pony Mail Foal (Next Generation Suite)
https://ponymail.apache.org
Apache License 2.0
24 stars 14 forks source link

Multi-threading issues; inconsistent locking #209

Open sebbASF opened 2 years ago

sebbASF commented 2 years ago

https://github.com/apache/incubator-ponymail-foal/blob/bb4a6642506f0bb2c5a2a67570433536c3b22f66/tools/import-mbox.py#L154

According to [1], list.pop() is thread-safe, so the lock should not be needed. However the documentation does not say that len(list) is thread-safe. If list.pop() does need to be protected by a lock, then surely [2] should be similarly protected?

The FAQ [1] does say that incrementing an integer is not atomic, so the various global counts might not be incremented properly.

[1] https://docs.python.org/3/faq/library.html#what-kinds-of-global-value-mutation-are-thread-safe [2] https://github.com/apache/incubator-ponymail-foal/blob/bb4a6642506f0bb2c5a2a67570433536c3b22f66/tools/import-mbox.py#L131

sebbASF commented 2 years ago

The len(lists) operation is done twice; it may change in between the calls.