diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index eb8adf0a..60f3a102 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -1515,7 +1515,7 @@ class HttpCli(object): with open_func(*open_args) as f: sendfun = sendfile_kern if use_sendfile else sendfile_py remains = sendfun( - lower, upper, f, self.s, self.args.s_wr_sz, self.args.s_wr_slp + self.log, lower, upper, f, self.s, self.args.s_wr_sz, self.args.s_wr_slp ) if remains > 0: diff --git a/copyparty/util.py b/copyparty/util.py index 95c98bca..475301ed 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -1177,7 +1177,7 @@ def hashcopy(fin, fout): return tlen, hashobj.hexdigest(), digest_b64 -def sendfile_py(lower, upper, f, s, bufsz, slp): +def sendfile_py(log, lower, upper, f, s, bufsz, slp): remains = upper - lower f.seek(lower) while remains > 0: @@ -1197,17 +1197,24 @@ def sendfile_py(lower, upper, f, s, bufsz, slp): return 0 -def sendfile_kern(lower, upper, f, s, bufsz, slp): +def sendfile_kern(log, lower, upper, f, s, bufsz, slp): out_fd = s.fileno() in_fd = f.fileno() ofs = lower + stuck = None while ofs < upper: + stuck = stuck or time.time() try: req = min(2 ** 30, upper - ofs) select.select([], [out_fd], [], 10) n = os.sendfile(out_fd, in_fd, ofs, req) + stuck = None except Exception as ex: - # print("sendfile: " + repr(ex)) + d = time.time() - stuck + log("sendfile stuck for {:.3f} sec: {!r}".format(d, ex)) + if d < 3600 and ex.errno == 11: # eagain + continue + n = 0 if n <= 0: