diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index ef7b7908..153a6763 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -115,7 +115,7 @@ class HttpCli(object): self.t0 = time.time() self.conn = conn - self.mutex = conn.mutex # mypy404 + self.u2mutex = conn.u2mutex # mypy404 self.s = conn.s self.sr = conn.sr self.ip = conn.addr[0] @@ -1988,8 +1988,11 @@ class HttpCli(object): except: raise Pebkac(500, min_ex()) - x = self.conn.hsrv.broker.ask("up2k.handle_json", body, self.u2fh.aps) - ret = x.get() + # not to protect u2fh, but to prevent handshakes while files are closing + with self.u2mutex: + x = self.conn.hsrv.broker.ask("up2k.handle_json", body, self.u2fh.aps) + ret = x.get() + if self.is_vproxied: if "purl" in ret: ret["purl"] = self.args.SR + ret["purl"] @@ -2094,7 +2097,7 @@ class HttpCli(object): f = None fpool = not self.args.no_fpool and sprs if fpool: - with self.mutex: + with self.u2mutex: try: f = self.u2fh.pop(path) except: @@ -2137,7 +2140,7 @@ class HttpCli(object): if not fpool: f.close() else: - with self.mutex: + with self.u2mutex: self.u2fh.put(path, f) except: # maybe busted handle (eg. disk went full) @@ -2156,7 +2159,7 @@ class HttpCli(object): return False if not num_left and fpool: - with self.mutex: + with self.u2mutex: self.u2fh.close(path) if not num_left and not self.args.nw: diff --git a/copyparty/httpconn.py b/copyparty/httpconn.py index 90f40a93..bf3690ab 100644 --- a/copyparty/httpconn.py +++ b/copyparty/httpconn.py @@ -50,7 +50,7 @@ class HttpConn(object): self.addr = addr self.hsrv = hsrv - self.mutex: threading.Lock = hsrv.mutex # mypy404 + self.u2mutex: threading.Lock = hsrv.u2mutex # mypy404 self.args: argparse.Namespace = hsrv.args # mypy404 self.E: EnvParams = self.args.E self.asrv: AuthSrv = hsrv.asrv # mypy404 diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py index 6e7daf9e..40bd108f 100644 --- a/copyparty/httpsrv.py +++ b/copyparty/httpsrv.py @@ -117,6 +117,7 @@ class HttpSrv(object): self.bound: set[tuple[str, int]] = set() self.name = "hsrv" + nsuf self.mutex = threading.Lock() + self.u2mutex = threading.Lock() self.stopping = False self.tp_nthr = 0 # actual @@ -220,7 +221,7 @@ class HttpSrv(object): def periodic(self) -> None: while True: time.sleep(2 if self.tp_ncli or self.ncli else 10) - with self.mutex: + with self.u2mutex, self.mutex: self.u2fh.clean() if self.tp_q: self.tp_ncli = max(self.ncli, self.tp_ncli - 2) diff --git a/tests/util.py b/tests/util.py index a91c1cce..3f0967ee 100644 --- a/tests/util.py +++ b/tests/util.py @@ -243,6 +243,7 @@ class VHttpConn(object): self.log_func = log self.log_src = "a" self.mutex = threading.Lock() + self.u2mutex = threading.Lock() self.nbyte = 0 self.nid = None self.nreq = -1