Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-541

Timeout used as specified by connectTimeoutMS will actually be less

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.5.0
    • Affects Version/s: 1.0.2
    • Component/s: libmongoc, network
    • Labels:
      None
    • Environment:
      CentOS 6.x / x86-64

      glibc 2.12 / gcc 4.4.7

      The value used as specified by the connectTimeoutMS option you specify will actually be less.

      In mongoc-client.c::mongoc_client_connect_tcp() we have

      104 expire_at = bson_get_monotonic_time () + (connecttimeoutms * 1000L);

      That value is then eventually passed down to mongoc-socket.c::_mongoc_socket_wait() where we have

      133 timeout = (int)((expire_at - bson_get_monotonic_time ()) / 1000L);

      Obviously at this point some amount of time will have already passed, so the time out will be less than what was specified. I'm seeing some quite large variations, with a connectTimeoutMS=100 I have seen the actual time out as low as 2.

      Also, seeing as the time out argument to poll(2) is simply a duration in milliseconds, as quoted from the man page

      "The timeout argument specifies the minimum number of milliseconds that
      poll() will block."

      Is there any reason to not just pass the connectTimeoutMS value as is?

      Cheers,
      Andrew

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            ac000 Andrew Clayton
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: