This repository contains samples that demonstrate best practices and general recommendations to communicate with Azure Redis Cache Service caches from various Redis client frameworks.
MIT License
69
stars
156
forks
source link
Incorrect order of replacing old connection with new one #38
- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)
Mention any other details that might be useful
From line 145 to line 159 there's the following logic:
Close the current connection
Replace _connection with null
Create a new connection
Replace _connection with the new connection
The issue is, that it opens a window for NullReferenceException and ObjectDisposedException exceptions:
Any thread holding the current connection reference after 1 has run, but before 2 has run will get an ObjectDisposedException.
Any thread using _connection after 2 has run and before 4 has run will get a NullReferenceException.
The correct order should be:
Create a new connection
Swap current connection with the new connection (atomic)
Dispose old connection - this one can still cause problems to any thread still using the connection, not sure what to do with it.
This issue is for a: (mark with an
x
)Mention any other details that might be useful
From line 145 to line 159 there's the following logic:
The issue is, that it opens a window for NullReferenceException and ObjectDisposedException exceptions:
The correct order should be: