Skip to content
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

Connection error with parallel testing #1709

Open
mahmoudyusof opened this issue Sep 6, 2021 · 6 comments
Open

Connection error with parallel testing #1709

mahmoudyusof opened this issue Sep 6, 2021 · 6 comments

Comments

@mahmoudyusof
Copy link

Describe the feature:

Elasticsearch version (bin/elasticsearch --version): 7.14.1

elasticsearch-py version (elasticsearch.__versionstr__): 7.14.1

Description of the problem including expected versus actual behavior: When running tests sequentially using pytest everything works fine, however, once I try to run tests in parallel using pytest -n=4 I get the following error:
elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x7f201879e978>: Failed to establish a new connection: [Errno 111] Connection refused) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x7f201879e978>: Failed to establish a new connection: [Errno 111] Connection refused)
I make sure before every test that the elasticsearch server is running, after this error I check the server status to see that is failed.

@sethmlarson
Copy link
Contributor

Our test suite isn't parallelizable in all cases due to setup and teardown of the Elasticsearch server. However when I try running with what I assume is pytest-xdist I don't receive connection errors, you're likely not running Elasticsearch properly for the test suite to connect to.

@mahmoudyusof
Copy link
Author

@sethmlarson I don't know why you closed the issue, the problem doesn't appear only with testing, it appears also when using uwsgi on multiple workers, parallel connections doesn't seem to work properly, it throws the same error and it stops the elasticsearch server

@mahmoudyusof
Copy link
Author

before running uwsgi I make sure to run sudo service elasticsearch status and it is running, after I run uwsgi it fails with the given error, and it shuts down elasticsearch servers

1 similar comment
@mahmoudyusof
Copy link
Author

before running uwsgi I make sure to run sudo service elasticsearch status and it is running, after I run uwsgi it fails with the given error, and it shuts down elasticsearch servers

@sethmlarson sethmlarson reopened this Sep 12, 2021
@sethmlarson
Copy link
Contributor

sethmlarson commented Sep 12, 2021

@mahmoudyusof Sorry for closing the issue early, you only mentioned thr test suite in your initial issue. Could you share details and code you're using for your web/worker so I can try reproducing the issue on Monday?

@mahmoudyusof
Copy link
Author

Configuration

sure, I am using uwsgi to serve a flask application with the configuration below

[uwsgi]
wsgi-file = wsgi.py
callable = app
socket = :8080
processes = 4
threads = 2
master = true
chmod-socket = 660
vacuum = true
die-on-term = true
cheaper = 0
lazy-apps = true
enable-threads=true
die-on-term = true
need-app = true
disable-logging = true
master = true

and as mentioned earlier, I make sure before running anything that the elasticsearch server is up and running

Code

I am using Elasticsearch client which is, as the documentation suggests, abstracts the handling of a connection pool
I define the client locally in the functions that uses it as follows

es = Elasticsearch("localhost:9200")

I've also tried defining the client globally and tried using a list instead of a string without any luck

es = Elasticsearch(["localhost:9200"])

Error

The code runs fine if I run flask the normal way (python app.py) however, when I run it using uwsgi on multiple processes and multiple threads, it shows the error mentioned in the first comment in this issue.
Same happens with testing, when I run tests sequentially everything runs fine, once I use xdist run tests in parallel, the same error shows up and the server of elasticsearch goes down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants