Fix issue#1371 - #1372
Conversation
|
Fix #1371 |
Signed-off-by: jiangteng <1@1.cn>
There was a problem hiding this comment.
Pull request overview
Improves the thread-safety of FeignHttpMessageConverters lazy initialization to address issue #1371 by preventing races when multiple threads request converters concurrently.
Changes:
- Make the cached
convertersfieldvolatileto ensure safe publication across threads. - Add double-checked locking around converter initialization and only assign the field after the list is fully built/customized.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: jiangteng <1@1.cn>
| for (int i = 0; i < threadCount; i++) { | ||
| executor.submit(() -> { | ||
| try { | ||
| startLatch.await(); // Wait for all threads to be ready | ||
|
|
||
| // First call - triggers initialization | ||
| List<?> firstResult = converters.getConverters(); | ||
| synchronized (results) { | ||
| results.add(firstResult); | ||
| } | ||
|
|
||
| // Second call - should return cached result | ||
| List<?> secondResult = converters.getConverters(); | ||
| assertThat(secondResult).isSameAs(firstResult); | ||
| } catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } finally { | ||
| endLatch.countDown(); | ||
| } | ||
| }); |
| // Wait for all threads to complete | ||
| endLatch.await(); | ||
| executor.shutdown(); | ||
|
|
| startLatch.countDown(); | ||
| endLatch.await(); | ||
| executor.shutdown(); | ||
|
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jason <20434877+jasonjiang9527@users.noreply.github.com>
| // TODO: allow disabling of registerDefaults | ||
| builder.registerDefaults(); | ||
| // TODO: check if already added? Howto order? | ||
| synchronized (this.convertersLock) { |
There was a problem hiding this comment.
Is there a specific reason to sync on another object than this?
There was a problem hiding this comment.
all the feign call thread will be blocked if another thread synchronize this but not release
|
Any news? Will this PR be resolved and merged? The bug causes a lot of problems with people need to manually fix their projects as workaround (see #1307). |
|
This is a major production issue for us. |
No description provided.