Skip to content

Commit 9b2d4b8

Browse files
ensure rclone is listening to the given port before trying to request noop
1 parent 8fbfa2f commit 9b2d4b8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Use storage on any of the many cloud providers `rclone <https://rclone.org/>`_ s
139139
- URL: ``rclone:remote:path``, we just prefix "rclone:" and give all to the right
140140
of that to rclone, see: https://rclone.org/docs/#syntax-of-remote-paths
141141
- implementation of this primarily depends on the specific remote.
142+
- rclone binary path can be set via the environment variable RCLONE_BINARY (default value: "rclone")
142143

143144

144145
Scalability

src/borgstore/backends/rclone.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from typing import Iterator
1212
import time
1313
import socket
14-
import random
1514

1615
from ._base import BackendBase, ItemInfo, validate_name
1716
from .errors import (
@@ -86,6 +85,14 @@ def find_open_port(self):
8685
s.bind((self.HOST, 0))
8786
return s.getsockname()[1]
8887

88+
def check_port(self, port):
89+
with socket.socket() as s:
90+
try:
91+
s.connect((self.HOST, port))
92+
return True
93+
except:
94+
return False
95+
8996
def open(self):
9097
"""
9198
Start using the rclone server
@@ -113,6 +120,8 @@ def open(self):
113120
self.url = "http://%s:%d/" % (self.HOST, port)
114121
# Wait for rclone to start up
115122
try:
123+
while self.process.poll() is None and not self.check_port(port):
124+
time.sleep(0.01)
116125
self.noop("noop")
117126
except:
118127
self.process.terminate()
@@ -197,6 +206,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
197206
return False
198207

199208
def noop(self, value) -> None:
209+
"""noop request that returns back the provided value <value>"""
200210
return self._rpc("rc/noop", { "value": value })
201211

202212
def mkdir(self, name: str) -> None:

0 commit comments

Comments
 (0)