plaintext is not threadsafe
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.9k
- Forks
- 1.6k
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
The plaintext function (https://github.com/clips/pattern/blob/master/pattern/web/__init__.py#L969)
Is not threadsafe as it's reusing HTMLTagstripper().strip.
It happens very rarely but scenario is as follows:
- two threads use the same HTMLTagstripper
- there are few places where the HTMLTagstripper appends new stuff to the _data attribute - in this case both threads do it .
- then we call return "".join(self._data) here:
https://github.com/clips/pattern/blob/master/pattern/web/__init__.py#L810 - we get data from both threads randomly joined.
Right now I rewrote the plaintext function to instatiate HTMLTagstripper every time, but
it would be amazing if there was a better way to make the plaintext function threadsafe.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read pattern/web/init.py at plaintext around line 969 and HTMLTagstripper.strip around line 810, then trace how the shared _data attribute is populated. Confirm concurrent calls cannot mix their output; the issue is done when each plaintext call returns only its own complete text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100