Previously, only the first task returned by docker was checked to find the running task. This commit checks all tasks instead so that the SwarmSpawner can tolerate tasks which failed to start.
When a user stops and rapidly restarts their server, the first few tasks of the newly created notebook service may fail to start due to the address still being in use. After several attempts, a task will start successfully, but fail to work correctly as poll() does not recognize that a running task exists.
The tasks returned don't seem to be ordered chronologically or by state, so task[-1] instead of task[0] does not solve the issue. I iterate over all tasks instead of returning as soon as possible so that the (seemingly arbitrary) order of tasks does not change which task states are logged.
Previously, only the first task returned by docker was checked to find the running task. This commit checks all tasks instead so that the SwarmSpawner can tolerate tasks which failed to start.
When a user stops and rapidly restarts their server, the first few tasks of the newly created notebook service may fail to start due to the address still being in use. After several attempts, a task will start successfully, but fail to work correctly as
poll()
does not recognize that a running task exists.The tasks returned don't seem to be ordered chronologically or by state, so
task[-1]
instead oftask[0]
does not solve the issue. I iterate over all tasks instead of returning as soon as possible so that the (seemingly arbitrary) order of tasks does not change which task states are logged.