avoid useless retries when a fatal error occurs

Adds "fatal" bool field to struct tip_client.

Fatal is looked for when cli->error is set, if fatal is set then no
retry is done and tiptorrent-client should terminate.
master v1.0.0
Jose M. Guisado 2022-09-29 10:45:20 +02:00
parent ec5b9dc003
commit edb59d4907
1 changed files with 12 additions and 3 deletions

View File

@ -61,6 +61,7 @@ struct tip_client {
int num_retries;
int fd;
bool error;
bool fatal;
bool redirected;
bool server_only;
struct timeval tv_start, tv_last;
@ -289,6 +290,7 @@ static int tip_client_head_hdr(struct tip_client *cli)
syslog(LOG_ERR, "failed to allocate room for file %s: %s",
filename, strerror(errno));
delete_file(filename);
cli->fatal = true;
return -1;
}
@ -501,6 +503,10 @@ static int tip_client_request_file(struct tip_client *cli,
ev_loop(tip_main_loop, 0);
if (cli->error) {
if (cli->fatal) {
syslog(LOG_ERR, "Fatal error, bailing out!\n");
return -1;
}
syslog(LOG_ERR, "Failed to fetch file %s\n", filename);
sleep(WAIT_RETRY);
if (cli->num_retries++ >= MAX_RETRIES) {
@ -581,7 +587,7 @@ int main(int argc, char *argv[])
} while (ret > 0);
if (ret < 0)
goto err_max_retries;
goto err_bailout;
if (_cli.state != TIP_CLIENT_DONE)
goto err;
@ -613,7 +619,7 @@ int main(int argc, char *argv[])
}
if (ret < 0)
goto err_max_retries;
goto err_bailout;
if (_cli.redirected)
tip_client_stats.redirects++;
@ -655,7 +661,10 @@ err:
tip_client_stats.redirects);
return EXIT_FAILURE;
err_max_retries:
err_bailout:
if (_cli.fatal)
return EXIT_FAILURE;
syslog(LOG_INFO, "Failure after maximum number of retries. "
"Direct from server: %u Redirected: %u\n",
tip_client_stats.direct_from_server,