Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-17922

C++ Thin: SIGSEGV on connection closed

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.14
    • 2.15
    • thin client
    • 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

          Activity

            People

              isapego Igor Sapego
              isapego Igor Sapego
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m