From 95968a625e91ae43aef9a4b810f93078dabe1419 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 10 Jan 2011 16:44:42 -0500 Subject: [PATCH 1/2] Wait 60 minutes before retrying failed state save; bug2346 --- changes/bug2346 | 5 +++++ src/or/config.c | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 changes/bug2346 diff --git a/changes/bug2346 b/changes/bug2346 new file mode 100644 index 0000000000..341b4f45bf --- /dev/null +++ b/changes/bug2346 @@ -0,0 +1,5 @@ + o Minor features + - If writing the state file to disk fails, wait an hour before + retrying again. Fixes bug 2346. Bugfix on Tor 0.1.1.3-alpha. + + diff --git a/src/or/config.c b/src/or/config.c index 17d776e71e..5198eaa055 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -5145,6 +5145,9 @@ or_state_load(void) return r; } +/** If writing the state to disk fails, try again after this many seconds. */ +#define STATE_WRITE_RETRY_INTERVAL 3600 + /** Write the persistent state to disk. Return 0 for success, <0 on failure. */ int or_state_save(time_t now) @@ -5179,10 +5182,13 @@ or_state_save(time_t now) tor_free(state); fname = get_datadir_fname("state"); if (write_str_to_file(fname, contents, 0)<0) { - log_warn(LD_FS, "Unable to write state to file \"%s\"", fname); + log_warn(LD_FS, "Unable to write state to file \"%s\"; will try later", + fname); global_state->LastWritten = -1; tor_free(fname); tor_free(contents); + /* Try again in after STATE_WRITE_RETRY_INTERVAL */ + global_state->next_write = now + STATE_WRITE_RETRY_INTERVAL; return -1; } From 5044cb9752b4414cadcdc3b12926b005e390fdf0 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 12 Jan 2011 12:37:42 -0500 Subject: [PATCH 2/2] Explain bug2346 fix better based on suggestions from arma --- changes/bug2346 | 5 +++-- src/or/config.c | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/changes/bug2346 b/changes/bug2346 index 341b4f45bf..0f78b84614 100644 --- a/changes/bug2346 +++ b/changes/bug2346 @@ -1,5 +1,6 @@ o Minor features - - If writing the state file to disk fails, wait an hour before - retrying again. Fixes bug 2346. Bugfix on Tor 0.1.1.3-alpha. + - If writing the state file to disk fails, wait up to an hour + before retrying again. (Our old code would retry the write + immediately.) Fixes bug 2346. Bugfix on Tor 0.1.1.3-alpha. diff --git a/src/or/config.c b/src/or/config.c index 5198eaa055..a27fd22b24 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -5187,7 +5187,8 @@ or_state_save(time_t now) global_state->LastWritten = -1; tor_free(fname); tor_free(contents); - /* Try again in after STATE_WRITE_RETRY_INTERVAL */ + /* Try again after STATE_WRITE_RETRY_INTERVAL (or sooner, if the state + * changes sooner). */ global_state->next_write = now + STATE_WRITE_RETRY_INTERVAL; return -1; }