[issue23191] fnmatch regex cache use is not threadsafe

2015-01-08 Thread M. Schmitzer

New submission from M. Schmitzer:

The way the fnmatch module uses its regex cache is not threadsafe. When 
multiple threads use the module in parallel, a race condition between 
retrieving a - presumed present - item from the cache and clearing the cache 
(because the maximum size has been reached) can lead to KeyError being raised.

The attached script demonstrates the problem. Running it will (eventually) 
yield errors like the following.

Exception in thread Thread-10:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
  File "fnmatch_thread.py", line 12, in run
fnmatch.fnmatchcase(name, pat)
  File "/home/marc/.venv/modern/lib/python2.7/fnmatch.py", line 79, in 
fnmatchcase
return _cache[pat].match(name) is not None
KeyError: 'lYwrOCJtLU'

--
components: Library (Lib)
files: fnmatch_thread.py
messages: 233650
nosy: mschmitzer
priority: normal
severity: normal
status: open
title: fnmatch regex cache use is not threadsafe
type: crash
versions: Python 2.7
Added file: http://bugs.python.org/file37642/fnmatch_thread.py

___
Python tracker 
<http://bugs.python.org/issue23191>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23191] fnmatch regex cache use is not threadsafe

2015-01-08 Thread M. Schmitzer

M. Schmitzer added the comment:

Ok, if that is the attitude in such cases, feel free to close this.

--

___
Python tracker 
<http://bugs.python.org/issue23191>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue23191] fnmatch regex cache use is not threadsafe

2015-01-08 Thread M. Schmitzer

M. Schmitzer added the comment:

@serhiy.storchaka: My thoughts exactly, especially regarding the caching being 
implicit. From the outside, fnmatch really doesn't look like it could have 
threading issues.
The patch also looks exactly like what I had in mind.

--

___
Python tracker 
<http://bugs.python.org/issue23191>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com