Fix recursive update issue in concurrent map for thumbnail generation (#7789)

#### What type of PR is this?

/kind bug
/area core
/milestone 2.22.x

#### What this PR does / why we need it:

This PR fixes recursive update issue in concurrent map for thumbnail generation.

```java
java.lang.IllegalStateException: Recursive update
	at java.base/java.util.concurrent.ConcurrentHashMap.replaceNode(Unknown Source) ~[na:na]
```

#### Does this PR introduce a user-facing change?

```release-note
None
```
pull/7791/head
John Niang 2025-10-02 18:22:25 +08:00 committed by GitHub
parent 43f41c3fc2
commit 300af1edc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 4 deletions

View File

@ -149,8 +149,7 @@ class ThumbnailRouters {
private Mono<Resource> generateThumbnail(
String filename, Path attachmentPath, Path thumbnailPath, ThumbnailSize size
) {
return Mono.fromFuture(() -> inProgress.computeIfAbsent(filename,
f ->
return Mono.fromFuture(() -> inProgress.computeIfAbsent(filename, f ->
CompletableFuture.supplyAsync(() -> generateThumbnail(
attachmentPath, thumbnailPath, size
),
@ -160,8 +159,10 @@ class ThumbnailRouters {
DEFAULT_GENERATION_TIMEOUT_SECONDS,
TimeUnit.SECONDS
)
.whenComplete((p, t) -> inProgress.remove(filename))
),
)
// Remove the entry from the map when the task is complete outside the
// computeIfAbsent to prevent the recursive update
.whenComplete((p, t) -> inProgress.remove(filename)),
// We don't want to cancel the thumbnail generation task
// when some requests are cancelled
true