{"action":"created","issue":{"url":"https://api.github.com/repos/tkem/cachetools/issues/115","repository_url":"https://api.github.com/repos/tkem/cachetools","labels_url":"https://api.github.com/repos/tkem/cachetools/issues/115/labels{/name}","comments_url":"https://api.github.com/repos/tkem/cachetools/issues/115/comments","events_url":"https://api.github.com/repos/tkem/cachetools/issues/115/events","html_url":"https://github.com/tkem/cachetools/issues/115","id":383558997,"node_id":"MDU6SXNzdWUzODM1NTg5OTc=","number":115,"title":"Ttl cache does not protect itself from KeyError when entry doesn't exist during expire()","user":{"login":"brunoais","id":639467,"node_id":"MDQ6VXNlcjYzOTQ2Nw==","avatar_url":"https://avatars0.githubusercontent.com/u/639467?v=4","gravatar_id":"","url":"https://api.github.com/users/brunoais","html_url":"https://github.com/brunoais","followers_url":"https://api.github.com/users/brunoais/followers","following_url":"https://api.github.com/users/brunoais/following{/other_user}","gists_url":"https://api.github.com/users/brunoais/gists{/gist_id}","starred_url":"https://api.github.com/users/brunoais/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brunoais/subscriptions","organizations_url":"https://api.github.com/users/brunoais/orgs","repos_url":"https://api.github.com/users/brunoais/repos","events_url":"https://api.github.com/users/brunoais/events{/privacy}","received_events_url":"https://api.github.com/users/brunoais/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-11-22T14:29:16Z","updated_at":"2018-11-22T15:02:13Z","closed_at":"2018-11-22T14:49:09Z","author_association":"NONE","body":"Problem:\r\n\r\nIn multithreaded environments, there's a high chance that [`def expire(self, time=None)`](https://github.com/tkem/cachetools/blob/master/cachetools/ttl.py#L170) is called concurrently.\r\nWhen that happens, there's a chance that `cache_delitem` (`Cache.__delitem__`) is called multiple times for the same element.\r\nWhen that function is called multiple times, the operator ends up executing `del` over the cache Mapping which causes an undocumented `KeyError` on all but first call to clear the cache entry.\r\n\r\nTo reproduce:\r\n1. Create a function with many calls. For example:\r\n\r\n```\r\nfrom threading import Thread\r\nimport cachetools\r\nimport random\r\n@cachetools.cached(cachetools.TTLCache(maxsize=50, ttl=1))\r\ndef will_not_be_called_sometimes(value):\r\n\timport time\r\n\ttime.sleep(value / 5)\r\nrandom.seed(5)\r\ndef run():\r\n\twhile True:\r\n\t\twill_not_be_called_sometimes(random.randrange(1, 30))\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nThread(target=run).start()\r\nrun()\r\n```\r\n\r\n2. Run as much as needed until the exception starts to appear.\r\n\r\nNote: In order to work, it might require running the program in a system with multiple CPU or CPU cores."},"comment":{"url":"https://api.github.com/repos/tkem/cachetools/issues/comments/441055939","html_url":"https://github.com/tkem/cachetools/issues/115#issuecomment-441055939","issue_url":"https://api.github.com/repos/tkem/cachetools/issues/115","id":441055939,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MTA1NTkzOQ==","user":{"login":"brunoais","id":639467,"node_id":"MDQ6VXNlcjYzOTQ2Nw==","avatar_url":"https://avatars0.githubusercontent.com/u/639467?v=4","gravatar_id":"","url":"https://api.github.com/users/brunoais","html_url":"https://github.com/brunoais","followers_url":"https://api.github.com/users/brunoais/followers","following_url":"https://api.github.com/users/brunoais/following{/other_user}","gists_url":"https://api.github.com/users/brunoais/gists{/gist_id}","starred_url":"https://api.github.com/users/brunoais/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brunoais/subscriptions","organizations_url":"https://api.github.com/users/brunoais/orgs","repos_url":"https://api.github.com/users/brunoais/repos","events_url":"https://api.github.com/users/brunoais/events{/privacy}","received_events_url":"https://api.github.com/users/brunoais/received_events","type":"User","site_admin":false},"created_at":"2018-11-22T15:02:12Z","updated_at":"2018-11-22T15:02:12Z","author_association":"NONE","body":"> \"all cache classes in this module\"\r\nYeah, that is a good improvement (I'm also awful with these stuff). Thank you."}}
{"actor":{"display_login":"brunoais"}}