[DATAREDIS-1034] RedisTemplate.opsFor* methods not thread-safe Created: 12/Sep/19  Updated: 30/Sep/19  Resolved: 25/Sep/19

Status: Closed
Project: Spring Data Redis
Component/s: Core
Affects Version/s: 2.1.10 (Lovelace SR10), 2.2 RC3 (Moore)
Fix Version/s: 2.1.11 (Lovelace SR11), 2.2 GA (Moore)

Type: Bug Priority: Minor
Reporter: cac03 Assignee: Mark Paluch
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11)
OpenJDK 64-Bit Server VM (build 11.0.4+11, mixed mode)

Model name: Intel(R) Core(TM) i5-3337U CPU @ 1.80GHz

5.2.11-arch1-1-ARCH GNU/Linux

Attachments: Zip Archive redis-template-datarace.zip    
Last updater: Mark Paluch
Pull Request URL: https://github.com/spring-projects/spring-data-redis/pull/479
Sprint: Moore RC2



(this is a follow-up of our conversation with Mark Paluch).


Some methods of RedisTemplate are not thread-safe:

  • A thread can get a null from the opsFor* methods (that create an instance of *Operations lazily)
  • A thread can fail with a NullPointerException when working with a not null instance returned from the opsFor* methods

I attached everything I had disclosed to Mark initially.
The archive contains tests to reproduce the issue, the original patch to fix it and elaborate explanation behind changes.

Mark suggested a little bit different solution to the problem.
I will send a pull request with the patch shortly.

(the original explanation is not inlined here because it is not applicable to the actual changes anymore)

Comment by cac03 [ 12/Sep/19 ]

Here is the pull request.

Please note that I also preinitialized DefaultClusterOperations


Thank you

Generated at Thu Oct 01 12:26:01 UTC 2020 using Jira 8.5.4#805004-sha1:0444eab799707f9ad7b248d69f858774aadfd250.