Comments (5)
Thanks for reporting this issue. I really appreciate your time spending on this report and also on the fix. I will have deeper look on the PR this evening or tomorrow morning.
Thank you!
from urlextract.
I am not able to reproduce it now. I will try that tomorrow on another machine.
from urlextract.
Interesting, I'm not able to reproduce locally now either. Apologies for the bad reproducer.
Perhaps I should add more details on this issue: I started encountering it about a week ago in a service that loads and instantiates this module in multiple processes, similar to the non-working reproduction script. This code had worked previously, but had recently increased the number of processes. I could occasionally get the service to start without error, but most starts resulted in the reported error while loading the cache file.
This behavior did not seem to present when performing an update repeatedly in a single thread. I assumed it was a race between reading/writing this cache file because of the non-determinism and it working in a single thread, but it's strange that this would suddenly stop reproducing. When I opened the PR, I tested the race with/without the locking and it succeeded/failed as expected.
My only only other guess is that this behavior was caused by intermittent bad responses from https://data.iana.org/TLD/tlds-alpha-by-domain.txt
that weren't being caught, but I unfortunately don't have response data from when I was encountering this bug to confirm that.
from urlextract.
Having dug a little more, the race just has a fairly tight window given the small size of the file and the default buffer size of 8192 bytes. I'm not sure why it suddenly became likely to happen for me last week. This diff on master will help reproduce, but in the absence of a race should have had no effect other than speed:
diff --git a/urlextract/cachefile.py b/urlextract/cachefile.py
index 5a59d58..6de41b0 100644
--- a/urlextract/cachefile.py
+++ b/urlextract/cachefile.py
@@ -181,7 +181,9 @@ class CacheFile:
try:
with urllib.request.urlopen(req) as f:
page = f.read().decode('utf-8')
- ftld.write(page)
+ for i in page:
+ ftld.write(i)
+ ftld.flush()
except HTTPError as e:
self._logger.error("ERROR: Can not download list ot TLDs. "
"(HTTPError: {})".format(e.reason))
With a single thread, this executes fine, but with multiple threads, it fails with a variety of errors.
from urlextract.
In addition to the exceptions, the much more common case is it returning an invalid TLD list. My guess is that, just by chance, the default buffer size caused the file last week to get cut off in a place that would cause an exception. This silent-failure behavior can be reproduced without the above diff:
from concurrent.futures import ThreadPoolExecutor
from urlextract import URLExtract
t = ThreadPoolExecutor(max_workers=8)
def test():
a = URLExtract()
a.update()
print('Number of TLDs: %d' % len(a._load_cached_tlds()))
for i in [t.submit(test) for _ in range(100)]:
b = i.result()
from urlextract.
Related Issues (20)
- Wrong indices when the domain name contains the same TLD twice HOT 3
- add types to urlextract HOT 3
- URLExtract no longer support Python 3.6 because of filelock recent changes
- TLD cache filelock error on read-only systems HOT 12
- Wrong indices with uppercase characters in domain name HOT 1
- Passing custom cache_dir doesnt seem to actually save the tlds...txt file in that dir
- IPv6? HOT 1
- left walk does not stop on various unicode chars HOT 1
- should not grab email fragments HOT 1
- comma extracted at the end if url ends with comma HOT 3
- travis-ci seems no longer active repository HOT 2
- URLExtract() init really slow
- ERROR: Can not download list of TLDs. (URLError: [Errno 104] Connection reset by peer) HOT 2
- Does Not extract the URL that is leading special character
- urlextract without authority causes AttributeError HOT 2
- Wrong indices and incomplete extraction when string contains similar urls HOT 1
- Handle upper-case false positives HOT 9
- Unable to detect t.me links HOT 1
- Bug with flag `allow_mixed_case_hostname=False` HOT 4
- Extracting Markdown Text, doesn't process escaped \\ correctly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from urlextract.