[CDRIVER-619] Fail fast after hangup with TLS Created: 14/Apr/15  Updated: 12/May/15  Resolved: 23/Apr/15

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

Type: Bug Priority: Blocker - P1
Reporter: A. Jesse Jiryu Davis Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible

 Description   

In 1.1.4, a network error at certain point(s) in the TLS code path causes the driver to spin infinitely.

To reproduce, first install pip, then mongo-mockup-db:

$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
$ sudo python -m pip install https://github.com/ajdavis/mongo-mockup-db/archive/master.zip

Then save this in a Python file and run it like "python file.py":

from mockupdb import MockupDB, Command
 
server = MockupDB(port=27017, auto_ismaster=True, verbose=True, ssl=True)
server.autoresponds('ping')
server.run()
server.receives(Command('listCollections'), timeout=100).hangup()

That'll wait up to 100 seconds for a driver to issue listCollections, then when it receives the command it hangs up.

I've started this mock server and run this file, using the C Driver built from master (0bd7850609):

#include <mongoc.h>
 
int
main (int   argc,
      char *argv[])
{
   mongoc_client_t *client;
   mongoc_database_t *db;
   bson_error_t error;
   mongoc_ssl_opt_t ssl_options = { 0 };
   const char *uristr = "mongodb://127.0.0.1/?ssl=true";
   char **names = NULL;
   int i = 0;
   mongoc_init ();
 
   if (argc > 1) {
      uristr = argv [1];
   }
 
   client = mongoc_client_new (uristr);
   ssl_options.weak_cert_validation = true;
   mongoc_client_set_ssl_opts (client, &ssl_options);
 
   if (!client) {
      fprintf (stderr, "Failed to parse URI.\n");
      return EXIT_FAILURE;
   }
 
   db = mongoc_client_get_database (client, "test");
   if ((names = mongoc_database_get_collection_names (db, &error))) {
      printf ("got collection names\n");
      for (i = 0; names [i]; i++)
         printf ("collection: %s\n", names [i]);
      bson_strfreev (names);
   } else {
      fprintf (stderr, "Command failed: %s\n", error.message);
   }
   mongoc_database_destroy (db);
   mongoc_client_destroy (client);
 
   mongoc_cleanup ();
 
   return EXIT_SUCCESS;
}

The Python server hangs up, and the client hangs and spins the CPU.

If I remove "ssl=True" from the Python and "ssl=true" from the C, and rerun both sides, I instead get an immediate log about the hangup from the C Driver and it exits as desired:

stream: Failure to buffer 4 bytes: Failed to buffer 4 bytes within 300000 milliseconds.

The C code also gets a non-NULL return value from mongoc_database_get_collection_names, which is filed as a separate bug CDRIVER-618.



 Comments   
Comment by Githook User [ 23/Apr/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@emptysquare.net'}

Message: Merge pull request #223 from ajdavis/CDRIVER-619-tls-loop-on-error

CDRIVER-619 fail fast after TLS socket hangup
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/2d331b7d68c922e502bc9242bbf8c2dea66e2bfa

Comment by Githook User [ 23/Apr/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@emptysquare.net'}

Message: Merge pull request #223 from ajdavis/CDRIVER-619-tls-loop-on-error

CDRIVER-619 fail fast after TLS socket hangup
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/2d331b7d68c922e502bc9242bbf8c2dea66e2bfa

Comment by Githook User [ 23/Apr/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-619 fail fast after TLS socket hangup
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/146b1f290dfdba9442bb1075e433675dadfadf02

Comment by Githook User [ 23/Apr/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-619 test TLS socket hangup
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/a7e9cfda2f2668b0e7b1e566d28fce08097b67e0

Comment by A. Jesse Jiryu Davis [ 21/Apr/15 ]

https://github.com/mongodb/mongo-c-driver/pull/223

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