Failing to write state file means you try every second
In or_state_save() we check
if (global_state->next_write > now) return 0;
but in the case where the save fails, we don't reset next_write. So we end up back in this function on the next second, failing to write again. That can't be good.
I say we set next_write to now + 3600 in the normal case, or TIME_MAX if AvoidDiskWrites is true. That way if it was a temporary problem it will for sure get retried pretty soon, but not that soon, and sooner if some other event happens that marks our state dirty again.
Bug is on 0.2.1.x and earlier too, but I think we can get away just fine with fixing it in maint-0.2.2 and later.
Bug pointed out by 'special' while hunting down #2077 (moved).