Repository navigation
Conversation
spring-cloudGH-3158 changed the bindings map back to a TreeMap with a case-insensitive comparator to restore case-insensitive binding names. That also dropped the thread safety added by spring-cloudgh-3011 and kept by spring-cloudgh-3076. The map is mutated on read: getBindingDestination(), getBindingProperties(), getProducerProperties() and getConsumerProperties() add a missing binding on first use (bindIfNecessary -> bindToDefault -> bindings.put). StreamBridge, BindingService and the binders call these from many threads without any lock. Concurrent first use of binding names corrupts the red-black tree: entries are lost, size() no longer matches the iteration, a NullPointerException is thrown from TreeMap.rotateRight (the failure reported in spring-cloudgh-3011) or a thread spins forever in TreeMap.successor while holding whatever monitor its caller holds, which stalls every thread that needs the bindings. Use a ConcurrentSkipListMap with String.CASE_INSENSITIVE_ORDER. It keeps what spring-cloudGH-3158 needs (case-insensitive lookup, original key casing, sorted iteration, same as the TreeMap) and is safe for concurrent use. A ConcurrentHashMap cannot be used because it is case-sensitive. The ConcurrentSkipListMap of spring-cloudgh-3011 was replaced by spring-cloudgh-3076 because of slower start-up. That issue's thread does not show the map as the cause: the reporter saw no improvement with the ConcurrentHashMap build and traced the slowdown to a Spring Boot change in how child contexts are created, plus binding properties placed under spring.cloud.config instead of spring.cloud.stream, which made every first getBinder() call take the bindToDefault() path. The new test, in BindingServiceTests, fails on the TreeMap (entries are lost or the map throws) and passes with this change. Fixes spring-cloudgh-3321 See spring-cloudgh-3011, spring-cloudgh-3076, spring-cloudgh-3158 Signed-off-by: Akash Bhogar <[email protected]> (cherry picked from commit 4f9b513) Signed-off-by: Akash Bhogar <[email protected]>
Make binding creation atomic in BindingServiceProperties Use putIfAbsent when registering default BindingProperties so that concurrent first use of the same binding name always yields a single shared instance. Previously, racing threads could each create and put their own instance, silently discarding mutations made on the loser. Resolves spring-cloud#3322 (cherry picked from commit 6412b30) Signed-off-by: Akash Bhogar <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #3322 (4f9b513) and its follow-up (6412b30) to
5.0.x. Both cherry-picked cleanly (-x, so each message names its source commit).5.0.xstill hasbindingsas a plainTreeMap(String.CASE_INSENSITIVE_ORDER)(GH-3158), which is not thread-safe. Concurrent first use of binding names, for exampleStreamBridge.send()from several threads, corrupts the map: lost entries,NullPointerExceptioninTreeMap.rotateRight, or a thread spinning forever inTreeMap.successor. Details are in #3321. The fix is already onmain; this brings it to the next 5.0.x patch.4f9b513d5:ConcurrentSkipListMap(String.CASE_INSENSITIVE_ORDER)plusBindingServiceTests#concurrentFirstUseOfBindingsKeepsTheMapConsistent.6412b305a: atomicputIfAbsentinbindIfNecessary, with its test changes.The
BindingServiceTestsfile is identical tomainafter the backport. I have not run the Maven build for this branch locally, so I am relying on CI.Refs #3321