question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTTP server doesn't closed

See original GitHub issue

What happened: When opening a client twice (or more) like the following code:

from dask.distributed import Client
with Client() as client:
    ...
...
with Client() as client:
    ...

or

from dask.distributed import Client
client = Client()
...
client.close()
...
client = Client()
...
client.close()

I`m getting the following warning massage when the new client opens (after one was created before):

/.../opt/anaconda3/envs/mlflow-env/lib/python3.7/site-packages/distributed/node.py:155: UserWarning: Port 8787 is already in use.
Perhaps you already have a cluster running?
Hosting the HTTP server on port 41137 instead
  http_address["port"], self.http_server.port

What you expected to happen: When a client is closed, it should also close the http_server thus releasing the port.

Minimal Complete Verifiable Example:

from dask.distributed import Client

with Client() as client:
    print(client)

with Client() as client:
    print(client)

Environment:

  • Dask version: 2.25.0
  • Python version: 3.7.9
  • Operating System: Linux
  • Install method (conda, pip, source): conda

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
TomAugspurgercommented, Oct 13, 2020

Are you relying on garbage collection to close your LocalCluster for you? It might be safer to use a context manager for it as well, given how complicated shutting down a cluster is.

0reactions
DavidKatz-ilcommented, Oct 13, 2020

Are you relying on garbage collection to close your LocalCluster for you? It might be safer to use a context manager for it as well, given how complicated shutting down a cluster is.

Thanks, this solves the problem.

In [1]: from time import sleep
   ...: from dask.distributed import Client, LocalCluster
   ...: 
   ...: with LocalCluster(dashboard_address=':3258') as cluster:
   ...:     with Client(cluster) as client:
   ...:         print(client)
   ...: sleep(10)
   ...: with LocalCluster(dashboard_address=':3258') as cluster:
   ...:     with Client(cluster) as client:
   ...:         print(client)
   ...: 
<Client: 'tcp://127.0.0.1:43337' processes=4 threads=8, memory=67.42 GB>
<Client: 'tcp://127.0.0.1:35661' processes=4 threads=8, memory=67.42 GB>
Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP server.close() does not shut down, process hangs #41895
This is a race condition caused by calling listen() and then immediately calling close() . Case 1 (correct behaviour): If the host parameter...
Read more >
Why "Hello, World!" exits but HTTP server doesn't?
You could terminate the server program by issuing server.close() after a while. It would then finish serving any pending connections and eventually exit....
Read more >
Can't close server (nodeJS) - Stack Overflow
The client is utilizing HTTP keep-alive. I think you will find that while the existing client can make new requests (as the connection...
Read more >
GIS / SI - HTTP Server Adapter doesn't shut down completely ...
2. Uncheck the adapter and re-enable it as soon as it shows up disabled. Be aware that this is not the proper procedure...
Read more >
How to terminate a HTTP server in Node.js?
i.e. when you call server.close() , server stops accepting new connections, but it keeps the existing connections open indefinitely. This can ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found