New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Haystack + Elasticsearch strange intermittent bug #1620
Comments
So there's clearly a problem with https://github.com/django-haystack/django-haystack/blob/master/haystack/utils/loading.py#L179 not handling the case where it gets no results. Since you have only one connection defined it's not immediately obvious why that's the case. |
Hi there! Is there something I could do to help? Specific tests or something? In addition to the details above, I noticed that although the error seems to occur "randomly", it is "more frequent" right after starting serving the application. For exemple on Django dev server (command |
Haystack is short on volunteer time so anything you can do to help with tests is appreciated. If I have a clean pull request with tests I’ll merge it when I get home next week.
|
I had the same error, it turns out it is a concurrency issue. There is a warning in the docs Switching from Below simplified haystack code which reproduces it: reproduce.py import random
from time import sleep
import threading
class DefaultRouter:
pass
class ConnectionRouter(object):
def __init__(self):
self._routers = None
@property
def routers(self):
if self._routers is None:
print("None")
router_list = [DefaultRouter]
sleep(0.3)
self._routers = []
sleep(0.3)
for router_class in router_list:
self._routers.append(router_class())
return self._routers
connection_router = ConnectionRouter()
def get_routers():
sleep(random.choice([0.3,0.5,0.1]))
return connection_router.routers[0]
threads = []
for i in range(10):
t = threading.Thread(target=get_routers)
threads.append(t)
for t in threads:
t.start()
for t in threads:
t.join() python reproduce.py λ python bla.py
None
None
None
None
None
None
None
None
None
Exception in thread Thread-10:
Traceback (most recent call last):
File "/home/User/.pyenv/versions/3.6.12/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/home/User/.pyenv/versions/3.6.12/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "reproduce.py", line 33, in get_routers
return connection_router.routers[0]
IndexError: list index out of range |
It looks like ConnectionRouter is not thread safe. My hacky workaround was to hardcode the backend and skip the connection router entirely:
A better fix would be to store |
@keeth wouldn't |
I'm facing a strange issue with Elasticsearch backend.
Everything works great (indexing, querying…), but sometimes (and sometimes only), querying the index crashes with this error:
The issue seems to be with the
_determine_backend function
.My backend is configured this way in Django settings file:
Expected behaviour
Search query should be issued to the search engine.
Actual behaviour
Fails at
backend_alias = connection_router.for_read(**hints)
Steps to reproduce the behaviour
Hard to reproduce: issue is intermittent. Happens about 10% of the time.
Configuration
The text was updated successfully, but these errors were encountered: