[CDRIVER-1220] Runtime Error: Assertion Failed Created: 04/May/16  Updated: 03/May/17  Resolved: 06/Jun/16

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.3.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: David P [X] Assignee: A. Jesse Jiryu Davis
Resolution: Cannot Reproduce Votes: 0
Labels: driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

ArchLinux, NGINX, FastCGI, g++



 Description   

I switched from C driver to C++ driver and that resolved my issues. However, I do not see why the C driver shouldn't have worked. Since I'm using more than one DBMS I wanted to keep the libraries managing them under the same language binding and not all of them have competent C++ bindings.

The runtime error is simply complaining about an assertion failing on

command = BCON_NEW ("ping", BCON_INT32 (1));

call from the tutorial at

http://api.mongodb.org/c/1.3.5/tutorial.html#connecting

I had to change passing in "ping" to char ping[] = "ping"; and pass in the variable instead of the string literal to get it to compile. This tutorial was inserted in a bare fastcgi program.

I compiled my program with the folllowing command:

g++ main.cpp -lfcgi -lfcgi++ -lmongoc-1.0 -lbson-1.0 --std=c++14



 Comments   
Comment by A. Jesse Jiryu Davis [ 06/Jun/16 ]

I'm closing this for now; if you can reproduce the error with a minimal code example that I can compile, please reopen this ticket and we'll investigate.

Comment by A. Jesse Jiryu Davis [ 08/May/16 ]

I installed GCC 4.9 (for C++14 support) on Ubuntu and attempted a minimal reproduction of your issue. I can't reproduce the error:

$ curl -LO https://github.com/mongodb/mongo-c-driver/releases/download/1.3.5/mongo-c-driver-1.3.5.tar.gz
$ tar xzf mongodb-linux-x86_64-ubuntu1404-3.2.4.tgz
$ cd mongo-c-driver
$ ./configure && make -j8 && sudo make install
$ cat > mongoc_test.cpp << EOF
#include <bson.h>
#include <bcon.h>
 
int main(void) {
   using namespace std;
 
   bson_t               *command;
 
   command = BCON_NEW("ping", BCON_INT32(1));
   printf ("%s\n", bson_as_json (command, NULL));
 
   return 0;
}
EOF
$ g++-4.9 mongoc_test.cpp -o mongoc_test -I /usr/local/include/libbson-1.0 -I /usr/local/include/libmongoc-1.0 -lmongoc-1.0 -lbson-1.0 --std=c++14
$ ./mongoc_test
{ "ping" : 1 }

The code compiles and works as expected using the BCON_NEW macro.

If you build this minimal source file on your system, do you get the assertion or does it work?

Comment by David P [X] [ 07/May/16 ]

When I use BCON_NEW() I get no errors. When I use bcon_new() I get the following error:

Runtime Error Message:

"mongoc_test: src/bson/bcon.c:789: bcon_append_ctx_va: Assertion `type == BCON_TYPE_UTF8' failed."

Compile Command:

g++ mongoc_test.cpp -o mongoc_test -I /usr/include/libbson-1.0 -I /usr/include/libmongoc-1.0 -lfcgi -lfcgi++ -lmongoc-1.0 -lbson-1.0

/**************************************************************************************/

#include <iostream>
#include "fcgio.h"

#include <bson.h>
#include <bcon.h>
#include <mongoc.h>

int main(void) {

using namespace std;

// Backup the stdio streambufs
streambuf * cin_streambuf = cin.rdbuf();
streambuf * cout_streambuf = cout.rdbuf();
streambuf * cerr_streambuf = cerr.rdbuf();

FCGX_Request request;

mongoc_client_t *client;
mongoc_database_t *database;
mongoc_collection_t *collection;
bson_t *command,
reply,
*insert;
bson_error_t error;
char *str;
bool retval;

FCGX_Init();
FCGX_InitRequest(&request, 0, 0);

mongoc_init();
client = mongoc_client_new("mongodb://localhost:27017");
database = mongoc_client_get_database(client, "NexigineUD");
collection = mongoc_client_get_collection(client, "NexigineUD", "Documents");

char ping[] = "ping";
command = bcon_new(ping, BCON_INT32(1));
retval = mongoc_client_command_simple (client, "admin", command, nullptr, &reply, &error);

while (FCGX_Accept_r(&request) == 0)

{ fcgi_streambuf cin_fcgi_streambuf(request.in); fcgi_streambuf cout_fcgi_streambuf(request.out); fcgi_streambuf cerr_fcgi_streambuf(request.err); cin.rdbuf(&cin_fcgi_streambuf); cout.rdbuf(&cout_fcgi_streambuf); cerr.rdbuf(&cerr_fcgi_streambuf); }

// restore stdio streambufs
cin.rdbuf(cin_streambuf);
cout.rdbuf(cout_streambuf);
cerr.rdbuf(cerr_streambuf);

return 0;
}

/******************************************************************************/

Comment by A. Jesse Jiryu Davis [ 05/May/16 ]

Can I see your main.cpp, please, and the complete output from your program's execution?

Is it possible to reproduce the failure with pure-C code compiled with GCC and no "--std" argument? I'm curious, since we're not yet testing and supporting standards beyond C99, and C++ circa 2003.

Generated at Wed Feb 07 21:11:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.