File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
s3stream/src/main/java/com/automq/stream Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -381,10 +381,11 @@ public CompletableFuture<Void> close(boolean force) {
381
381
382
382
// await all pending append/fetch/trim request
383
383
List <CompletableFuture <?>> pendingRequests = new ArrayList <>(pendingAppends );
384
+ // add timeout to prevent the fetch(catch-up read) network throttle to block Stream#close.
384
385
if (GlobalSwitch .STRICT ) {
385
- pendingRequests .addAll (pendingFetches );
386
+ pendingRequests .addAll (FutureUtil . timeoutAndSilence ( pendingFetches . stream (), 10 , TimeUnit . SECONDS ) );
386
387
}
387
- pendingRequests .add (lastPendingTrim );
388
+ pendingRequests .add (FutureUtil . timeoutAndSilence ( lastPendingTrim , 10 , TimeUnit . SECONDS ) );
388
389
if (force ) {
389
390
pendingRequests .forEach (cf -> cf .completeExceptionally (new StreamClientException (ErrorCode .UNEXPECTED , "FORCE_CLOSE" )));
390
391
}
Original file line number Diff line number Diff line change 23
23
import org .slf4j .LoggerFactory ;
24
24
25
25
import java .util .Iterator ;
26
+ import java .util .List ;
26
27
import java .util .concurrent .CompletableFuture ;
27
28
import java .util .concurrent .CompletionException ;
28
29
import java .util .concurrent .ExecutionException ;
31
32
import java .util .concurrent .TimeoutException ;
32
33
import java .util .concurrent .atomic .AtomicLong ;
33
34
import java .util .function .Supplier ;
35
+ import java .util .stream .Collectors ;
36
+ import java .util .stream .Stream ;
34
37
35
38
import io .netty .util .HashedWheelTimer ;
36
39
import io .netty .util .Timeout ;
@@ -165,4 +168,11 @@ public static <T> CompletableFuture<T> timeoutWithNewReturn(CompletableFuture<T>
165
168
return newCf ;
166
169
}
167
170
171
+ public static List <CompletableFuture <?>> timeoutAndSilence (Stream <CompletableFuture <?>> stream , long timeout , TimeUnit timeUnit ) {
172
+ return stream .map (l -> timeoutAndSilence (l , timeout , timeUnit )).collect (Collectors .toList ());
173
+ }
174
+
175
+ public static <T > CompletableFuture <T > timeoutAndSilence (CompletableFuture <T > cf , long timeout , TimeUnit timeUnit ) {
176
+ return cf .orTimeout (timeout , timeUnit ).exceptionally (ex -> null );
177
+ }
168
178
}
You can’t perform that action at this time.
0 commit comments