Time-limit options are not being checked enough (#179)
authorRodrigo Osorio <rodrigo@osorio.me>
Sun, 2 Jan 2022 22:37:27 +0000 (23:37 +0100)
committerGitHub <noreply@github.com>
Sun, 2 Jan 2022 22:37:27 +0000 (14:37 -0800)
The `--stop-at`, `--stop-after`, and `--time-limit`` options should have their
limit checked when receiving and sending data, not just when receiving.
Fixes #177.

io.c

diff --git a/io.c b/io.c
index abb0f7ab1e0b2da6589778affb82f3dc8a02e866..8b5c690fab2422f1e4c8033cf1c89029aab3cb2b 100644 (file)
--- a/io.c
+++ b/io.c
@@ -801,12 +801,8 @@ static char *perform_io(size_t needed, int flags)
                                        who_am_i(), (SIZE_T_FMT_CAST)n);
                        }
 
-                       if (io_timeout || stop_at_utime) {
+                       if (io_timeout) {
                                last_io_in = time(NULL);
-                               if (stop_at_utime && last_io_in >= stop_at_utime) {
-                                       rprintf(FERROR, "stopping at requested limit\n");
-                                       exit_cleanup(RERR_TIMEOUT);
-                               }
                                if (io_timeout && flags & PIO_NEED_INPUT)
                                        maybe_send_keepalive(last_io_in, 0);
                        }
@@ -815,6 +811,11 @@ static char *perform_io(size_t needed, int flags)
                        iobuf.in.len += n;
                }
 
+               if (stop_at_utime && time(NULL) >= stop_at_utime) {
+                       rprintf(FERROR, "stopping at requested limit\n");
+                       exit_cleanup(RERR_TIMEOUT);
+               }
+
                if (out && FD_ISSET(iobuf.out_fd, &w_fds)) {
                        size_t len = iobuf.raw_flushing_ends_before ? iobuf.raw_flushing_ends_before - out->pos : out->len;
                        ssize_t n;