[CDRIVER-1081] "Aborted" mongoc_collection_insert depending on key length Created: 03/Feb/16  Updated: 03/May/17  Resolved: 16/Mar/16

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

Type: Bug Priority: Major - P3
Reporter: Victor Matuzenko Assignee: A. Jesse Jiryu Davis
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux 3.10.69-25 x86_64 GNU/Linux
MongoDB 2.6.1 (server)
mongo-c-driver 1.1.4



 Description   

If I pass to function mongoc_collection_insert a document containing large (more than 1010 bytes) key field (which is involved in several indexes), the function crashes with "Aborted" message. This behaviour is observed every time with large key field and has not been reproduced with keys smaller than 1000. Also it seems adding many non-key fields don't trigger such crash.

It seems actually problem is exceeding the limit on indexed key size. It will be better if this function returns an error instead of instantly crashing in this case.

Last lines of strace log started after mongoc_collection_insert had been called (some private information hidden with **HIDDEN** marker):

uname({sys="Linux", node="***HIDDEN***", ...}) = 0
futex(0x8624890, FUTEX_WAKE_PRIVATE, 2147483647) = 0
poll([{fd=5, events=POLLIN|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
sendmsg(5, {msg_name(0)=NULL, msg_iov(9)=[{"\317\4\0\0", 4}, {"\361\0\0\0", 4}, {"\0\0\0\0", 4}, {"\324\7\0\0", 4}, {"\0\0\0\0", 4}, {"***HIDDEN***.$cmd\0", 12}, {"\0\0\0\0", 4}, {"\1\0\0\0", 4}, {"\247\4\0\0\2insert\0\5\0\0\0keys\0\3writeConce"..., 1191}], msg_controllen=0, msg_flags=0}, MSG_NOSIGNAL) = 1231
recvfrom(5, 0x7fc9cf400000, 8388608, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=5, events=POLLIN|POLLERR|POLLHUP}], 1, 299999) = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "\301\1\0\0\2\203\265]\361\0\0\0\1\0\0\0\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 8388608, 0, NULL, NULL) = 449
rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0
tgkill(31979, 31979, SIGABRT)           = 0
--- SIGABRT (Aborted) @ 0 (0) ---
+++ killed by SIGABRT +++



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

Hi, using MongoDB 2.6.11, I made an index:

> db.test_insert_oversize_val.createIndex({a: 1})
{
	"createdCollectionAutomatically" : true,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}

And attempted to reproduce your crash with the following code:

static void
test_insert_oversize_val (void)
{
  mongoc_client_t *client;
  mongoc_collection_t *collection;
  char *val;
  bson_t doc = BSON_INITIALIZER;
  bson_error_t error;
  bool r;
 
  client = mongoc_client_new(NULL);
  collection = mongoc_client_get_collection (client, "test", "test_insert_oversize_val");
 
  val = bson_malloc0 (2048);
  memset (val, 'a', 2047);
  BSON_APPEND_UTF8 (&doc, "a", val);
  r = mongoc_collection_insert (collection, MONGOC_INSERT_NONE, &doc, NULL,
                                &error);
  ASSERT (!r);
  printf ("error: %d %d %s\n", error.domain, error.code, error.message);
 
  bson_destroy (&doc);
  bson_free (val);
  mongoc_collection_destroy(collection);
  mongoc_client_destroy(client);
}

The driver does not abort, and instead prints, as expected:

error: 11 17280 insertDocument :: caused by :: 17280 Btree::insert: key too large to index, failing test.test_insert_oversize_val.$a_1 2060
{ : "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." }

I'm closing this for now, please feel free to re-open the ticket if the problem persists for you. If you do re-open this, please show me how you create the index, and some C code that creates the document that causes the crash. Thanks.

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