Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1676

As a user of TNonBlockingServer, I want the option to bind to a specific interface to service requests

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.8
    • 0.11.0
    • C++ - Library
    • None
    • Mac OS X. Thrift 0.8.0.

    Description

      Thrift doesn't allow users to specify which IP/hostname to use for bind. As a result, a Thrift server usually ends up listening on ALL interfaces on a machine (bind uses INADDR_ANY). This is clearly undesirable in many cases where we may want to restrict connectivity to localhost or to within a particular subnet or targeted towards a specific host or IP.

      Here's a example of what TNonblockingServer does:

      // Wildcard address
        error = getaddrinfo(NULL, port, &hints, &res0);
        if (error) {
          throw TException("TNonblockingServer::serve() getaddrinfo " +
                           string(gai_strerror(error)));
        }
      
        // Pick the ipv6 address first since ipv4 addresses can be mapped
        // into ipv6 space.
        for (res = res0; res; res = res->ai_next) {
          if (res->ai_family == AF_INET6 || res->ai_next == NULL)
            break;
        }
      

      As can be seen, the above code fragment provides NULL as the first param to getaddrinfo and always specifies AI_PASSIVE. This results in the behavior I described above.

      A better approach IMO is to provide the following interface instead:

      TServer::serve(const char* hostOrIp, int port)
      

      This is consistent with what other modern server frameworks do (node.js, netty etc.)

      Attachments

        Issue Links

          Activity

            People

              jking3 James E. King III
              diwaker Diwaker Gupta
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: