Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-2289

Can't use resume_token after program restart

      Hello,

      I have an issue with change_streams and resume_tokens.
      Here is my use case : I have a server that read a collection and uses change_stream to sync to it. it uses a specific thread that has a while loop that constantly reads the change_stream.

      while (true)
      {
        auto changeStream = collection.watch(changeStreamPipeline);
        if(changeStream.begin() != changeStream.end())
        {
          for(const auto& change : changeStream)
          {
            auto document = change["fullDocument"].get_document();
            std::string jsonChangeString = bsoncxx::to_json(document);
            resumeToken = changeStream.get_resume_token();
            /* Compute index */
          }
        }
      }
      

      Where resumeToken is a class member.

       

       

      Then the resume token is saved as a string. in a struct called indexer_data

       

      boost::archive::binary_oarchive         archive(ofs);
      IndexerData                             indexer_data;
      
      std::string data = bsoncxx::to_json(_lastResumeToken.get());
      indexer_data.lastResumeToken   = data;
      
      archive << indexer_data;
      

       

       

      Then when the server restart the archive is read and we try to resume the stream from the resumeToken

       

      mongocxx::pipeline changeStreamPipeline;
      changeStreamPipeline.match(bsoncxx::builder::basic::make_document(bsoncxx::builder::basic::kvp("operationType", "insert")));
      mongocxx::options::change_stream changeStreamOptions;
      if(!savedResumeToken.empty())
      {
        auto resumeToken = bsoncxx::from_json(savedResumeToken);
        changeStreamOptions.resume_after(resumeToken);
      }
      
      
      auto changeStream = collection.watch(changeStreamPipeline, changeStreamOptions); // CRASH HERE
      
      /* Loop to get the changes from the change stream */
      

      When we try to watch the collection with the options with the resumeToken, there is a crash, a SEGFAULT.
      Is it a known bug, do I use the resume_token the wrong way ?
      Note that it also happens if the resume_token is passed with the "start_after" option.

      Thanks in advance

       

       

            Assignee:
            ezra.chung@mongodb.com Ezra Chung
            Reporter:
            maxime.guillem@systrangroup.com Maxime Guillem
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: