|
1 | 1 | package org.cryptomator.cryptofs.inuse; |
2 | 2 |
|
3 | | -import org.cryptomator.cryptofs.common.Constants; |
4 | 3 | import org.cryptomator.cryptofs.common.EncryptedChannels; |
5 | 4 | import org.cryptomator.cryptolib.api.Cryptor; |
6 | 5 | import org.slf4j.Logger; |
@@ -92,20 +91,25 @@ private void scheduleRefresh(int count) { |
92 | 91 | } |
93 | 92 |
|
94 | 93 | var delayedExecutor = delayExponentiallyWithCap(tokenPersistor, count); |
95 | | - var nextPersistenceTask = currentTask.thenRunAsync(() -> { |
| 94 | + var nextPersistenceTask = currentTask.thenRunAsync(() -> runRefresh(count), delayedExecutor); |
| 95 | + tokenPersistenceTask.set(nextPersistenceTask); |
| 96 | + } |
| 97 | + |
| 98 | + private void runRefresh(int count) { |
| 99 | + try { |
| 100 | + CONCURRENT_WRITES_SEMAPHORE.acquire(); |
96 | 101 | try { |
97 | | - CONCURRENT_WRITES_SEMAPHORE.acquire(); |
98 | 102 | refresh(); |
99 | | - CONCURRENT_WRITES_SEMAPHORE.release(); |
100 | 103 | scheduleRefresh(count + 1); |
101 | | - } catch (InterruptedException e) { |
102 | | - LOG.debug("Interrupt during refresh of {}. Closing token.", filePath); |
103 | | - close(); |
104 | | - Thread.currentThread().interrupt(); |
105 | | - throw new RuntimeException(e); |
| 104 | + } finally { |
| 105 | + CONCURRENT_WRITES_SEMAPHORE.release(); |
106 | 106 | } |
107 | | - }, delayedExecutor); |
108 | | - tokenPersistenceTask.set(nextPersistenceTask); |
| 107 | + } catch (InterruptedException e) { |
| 108 | + LOG.debug("Interrupt during refresh of {}. Closing token.", filePath); |
| 109 | + close(); |
| 110 | + Thread.currentThread().interrupt(); |
| 111 | + throw new RuntimeException(e); //mark the completion stage as failed |
| 112 | + } |
109 | 113 | } |
110 | 114 |
|
111 | 115 | private Executor delayExponentiallyWithCap(Executor executor, int count) { |
|
0 commit comments