Skip to content

ConnectionRefused on first attempt at exporting image #164

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

Closed
dwjp opened this issue Dec 4, 2018 · 2 comments
Closed

ConnectionRefused on first attempt at exporting image #164

dwjp opened this issue Dec 4, 2018 · 2 comments

Comments

@dwjp
Copy link

dwjp commented Dec 4, 2018

I'm running orca in a miniconda container, which is in turn running as a celery service (though probably not relevant).

On the first one or two attempts at generating an image (when kicking off at about the same time, but on separate processes), I get connection refused. On subsequent tries, it works fine, everytime.

At a guess, I suspect the python client isn't waiting long enough for orca to start, but makes it through on a warm restart when orca starts a bit quicker?

File "/opt/conda/lib/python2.7/site-packages/plotly/io/_orca.py", line 1298, in to_image
height=height)
File "/opt/conda/lib/python2.7/site-packages/retrying.py", line 49, in wrapped_f
return Retrying(*dargs, **dkw).call(f, *args, **kw)
File "/opt/conda/lib/python2.7/site-packages/retrying.py", line 212, in call
raise attempt.get()
File "/opt/conda/lib/python2.7/site-packages/retrying.py", line 247, in get
six.reraise(self.value[0], self.value[1], self.value[2])
File "/opt/conda/lib/python2.7/site-packages/retrying.py", line 200, in call
attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
File "/opt/conda/lib/python2.7/site-packages/plotly/io/_orca.py", line 1205, in request_image_with_retrying
response = requests.post(server_url + '/', data=json_str)
File "/opt/conda/lib/python2.7/site-packages/requests/api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "/opt/conda/lib/python2.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/opt/conda/lib/python2.7/site-packages/requests/sessions.py", line 518, in request
resp = self.send(prep, **send_kwargs)
File "/opt/conda/lib/python2.7/site-packages/requests/sessions.py", line 639, in send
r = adapter.send(request, **kwargs)
File "/opt/conda/lib/python2.7/site-packages/requests/adapters.py", line 502, in send
raise ConnectionError(e, request=request)
ConnectionError: HTTPConnectionPool(host='localhost', port=45166): Max retries exceeded with url: / (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7f7ba9543550>: Failed to establish a new connection: [Errno 111] Connection refused',))

@ociule
Copy link

ociule commented Dec 4, 2018

I've seen this behaviour enough times for it to become very annoying, I would appreciate a robust retry policy. Thanks.

PS: running orca on Windows 7, through Git bash or cmd.

@jonmmease
Copy link
Contributor

Hi @dwjp and @ociule,

Thanks for letting us know. What's happening here is that plotly.py launches orca as a server process the first time you export an image. It does have a robust retry policy for communicating with the server, it just currently gives up after 8 seconds 🙂

https://github.com/plotly/plotly.py/blob/a9fa5de705d86a229eca988ec1f5ed5069d91dc0/plotly/io/_orca.py#L1194

This number is admittedly a bit arbitrary, and it sounds like we should increase it. I've opened a plotly.py issue for this at plotly/plotly.py#1297.

In the meantime, here's a workaround. You can ask plotly.py to start the orca process manually (before you call write_image) by calling plotly.io.orca.ensure_server(). So you can add something like this to the top of your script/notebook

import plotly
import time
plotly.io.orca.ensure_server()
time.sleep(10)

This will give the server an extra 10 seconds to startup (in addition to the 8 seconds that write_image will retry for).

I'm going to close this issue in favor of plotly/plotly.py#1297 since this is a plotly.py, not orca, issue. Thanks!

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

3 participants