Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
2.14
-
None
-
C++ thin client: Fixrd SIGSEGV on connection closed
-
Docs Required, Release Notes Required
Description
Let’s consider some simple program:
#include <ignite/thin/ignite_client.h> #include <iostream> #include <thread> #include <chrono> int main() { ignite::thin::IgniteClientConfiguration cfg; cfg.SetEndPoints("127.0.0.1"); cfg.SetConnectionTimeout(2000); auto client = ignite::thin::IgniteClient::Start(cfg); auto cache = client.GetOrCreateCache<int64_t, int64_t>("person"); try { while (true) { int64_t size; try { size = cache.GetSize(4); std::cout << size << "\n"; } catch (ignite::IgniteError& e) { std::cerr << e.what() << "\n"; } std::this_thread::sleep_for(std::chrono::milliseconds{1000}); } } catch (...) { std::cerr << "Exception thrown\n"; } }
During server restart this program could crash because of data race.
It seems problem here: DataRouter::OnConnectionClosed.
void DataRouter::OnConnectionClosed(uint64_t id, const IgniteError* err) { SP_DataChannel channel; { common::concurrent::CsLockGuard lock(channelsMutex); channel = FindChannelLocked(id); connectedChannels.erase(id); InvalidateChannelLocked(channel); } channel.Get()->FailPendingRequests(err); }
Local variable channel initialized as nullptr, thus calling channel.Get()-> yields signal throw.
It seems FindChannelLocked call was unsuccessful, because objected was deleted in another thread (in this example most likely in main thread during GetSize)
I suggest WA to check SP_DataChannel state before dereferencing it.
Attachments
Issue Links
- is duplicated by
-
IGNITE-17971 Nullptr access in thin c++ client in OnConnectionClosed
- Resolved
- links to