Skip to content

distributed.get_client() can return a closed client #2840

Closed

Description

@pierreglaser

In the following reproducer:

from distributed import get_client, Client, LocalCluster
import scipy  # required to trigger the bug, probably by slowing the gc


def inc(i):
    return i + 1


if __name__ == "__main__":
    cluster = LocalCluster(n_workers=0, processes=False, threads_per_worker=2)

    c = Client(cluster)
    cluster.scale(2)
    assert c == get_client()
    print(cluster)

    c.close()
    cluster.close()
    # import gc; gc.collect()

    cluster2 = LocalCluster(n_workers=0, processes=False, threads_per_worker=2)
    c2 = Client(cluster2)
    cluster2.scale(2)
    print(cluster2)

    current_client = get_client()
    assert c2 == current_client

    print("OK")

I create one Cluster and bind a client to it. After closing them, I re-create a new cluster and a new client, but get_client() tries to connect to the old, closed client -- because it has been closed, an OSError is raised:

Traceback (most recent call last):                                                                                                                                                                                 
  File "/home/pierreglaser/repos/distributed/distributed/comm/core.py", line 218, in connect                                                                                                                       
    quiet_exceptions=EnvironmentError,                                                                                                                                                                             
  File "/home/pierreglaser/.virtualenvs/joblib_py37/lib/python3.7/site-packages/tornado/gen.py", line 1133, in run                                                                                                 
    value = future.result()                                                                                                                                                                                        
  File "/home/pierreglaser/.virtualenvs/joblib_py37/lib/python3.7/site-packages/tornado/gen.py", line 326, in wrapper                                                                                              
    yielded = next(result)                                                                                                                                                                                         
  File "/home/pierreglaser/repos/distributed/distributed/comm/inproc.py", line 296, in connect                                                                                                                     
    raise IOError("no endpoint for inproc address %r" % (address,))                                                                                                                                                
OSError: no endpoint for inproc address '10.200.21.15/24632/1'                                                                                                                                                     
                                                                                                                                                                                                                   
During handling of the above exception, another exception occurred:                                                                                                                                                
                                                                                                                                                                                                                   
Traceback (most recent call last):                                                                                                                                                                                 
  File "test_client_distributed.py", line 26, in <module>                                                                                                                                                          
    current_client = get_client()                                                                                                                                                                                  
  File "/home/pierreglaser/repos/distributed/distributed/worker.py", line 2911, in get_client                                                                                                                      
    return worker._get_client(timeout=timeout)                                                                                                                                                                     
  File "/home/pierreglaser/repos/distributed/distributed/worker.py", line 2810, in _get_client                                                                                                                     
    timeout=timeout,                                                                                                                                                                                               
  File "/home/pierreglaser/repos/distributed/distributed/client.py", line 722, in __init__                                                                                                                         
    self.start(timeout=timeout)                                                                                                                                                                                    
  File "/home/pierreglaser/repos/distributed/distributed/client.py", line 872, in start                                                                                                                            
    sync(self.loop, self._start, **kwargs)                                                                                                                                                                         
  File "/home/pierreglaser/repos/distributed/distributed/utils.py", line 332, in sync                                                                                                                              
    six.reraise(*error[0])                                                                                                                                                                                         
  File "/home/pierreglaser/.virtualenvs/joblib_py37/lib/python3.7/site-packages/six.py", line 693, in reraise                                                                                                      
    raise value                                                                                                                                                                                                    
  File "/home/pierreglaser/repos/distributed/distributed/utils.py", line 317, in f                                                                                                                                 
    result[0] = yield future                                                                                                                                                                                       
  File "/home/pierreglaser/.virtualenvs/joblib_py37/lib/python3.7/site-packages/tornado/gen.py", line 1133, in run                                                                                                 
    value = future.result()                                                                                                                                                                                        
  File "/home/pierreglaser/.virtualenvs/joblib_py37/lib/python3.7/site-packages/tornado/gen.py", line 1141, in run                                                                                                 
    yielded = self.gen.throw(*exc_info)                                                                                                                                                                            
  File "/home/pierreglaser/repos/distributed/distributed/client.py", line 968, in _start                                                                                                                           
    yield self._ensure_connected(timeout=timeout)                                                                                                                                                                  
  File "/home/pierreglaser/.virtualenvs/joblib_py37/lib/python3.7/site-packages/tornado/gen.py", line 1133, in run                                                                                                 
    value = future.result()                                                                                                                                                                                        
  File "/home/pierreglaser/.virtualenvs/joblib_py37/lib/python3.7/site-packages/tornado/gen.py", line 1141, in run                                                                                                 
    yielded = self.gen.throw(*exc_info)                                                                                                                                                                            
  File "/home/pierreglaser/repos/distributed/distributed/client.py", line 1024, in _ensure_connected                                                                                                               
    connection_args=self.connection_args,                                                                                                                                                                          
  File "/home/pierreglaser/.virtualenvs/joblib_py37/lib/python3.7/site-packages/tornado/gen.py", line 1133, in run                                                                                                 
    value = future.result()                                                                                                                                                                                        
  File "/home/pierreglaser/.virtualenvs/joblib_py37/lib/python3.7/site-packages/tornado/gen.py", line 1141, in run                                                                                                 
    yielded = self.gen.throw(*exc_info)                                                                                                                                                                            
  File "/home/pierreglaser/repos/distributed/distributed/comm/core.py", line 228, in connect                                                                                                                       
    _raise(error)                                                                                                                                                                                                  
  File "/home/pierreglaser/repos/distributed/distributed/comm/core.py", line 207, in _raise                                                                                                                        
    raise IOError(msg)                                                                                                                      

Activity

  1. changed the title [-]distributed.get_client() can return a closed cluster[/-] [+]distributed.get_client() can return a closed client[/+] on Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions