Web lists-archives.com

RPC clnt_create() adress already in use




In our environment we have a Linux-Server and several Windows-PCs (Windows XP SP3, in the past Windows NT too). On the Linux-Server RPC-Services (Remote Procedure Call) are running, one service for one Windows-PC each. To build the RPC-clients on the Windows-boxes, I used Cygwin 1.5.18 and actually Cygwin 2.5.1 (because we now have Windows 7 too).

The RPC-Client (*.exe) on the Windows-box is started at any time by hand, establishes a connection to the server (clnt_create), executes a few calls to the server (clnt_call), closes the connection (clnt_destroy) and exits. The time-interval between the program starts can be 10 seconds up to 2 minutes.

This worked over many years without any error (Cygwin 1.5.18).
Now I upgraded to Cygwin 2_5_1 (libtirpc instead librpc) and there are problems. Sometimes the RPC-Client cannot establish a connection to the server. The error message from clnt_spcreateerror():

Remote system error - Address already in use

I think it is "EADDRINUSE".

I wrote a program for tests in Cygwin 1.5.18, 1.7.32 and 2.5.1:

The program reads argv[1] as a sleeptime. If no argv[1] exists, sleeptime has a default value of  10 seconds. Afterwards is a loop (20 times) of the following actions:

-       establish a connection to the server and sleep for 1 second

-       destroy the connection

-       sleep(sleeptime)

test_rpc.c:


/*=================*/
/*  Include-Files  */
/*=================*/
#include <stdio.h>
#include <stdlib.h>
#include <curses.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
/*#include <posix.h>*/
#include <sys/types.h>
#include <sys/stat.h>

#include <rpc/rpc.h>

/*===========================================*/
/*  global definitions                                                              */
/*===========================================*/

char local_errmsg[512];

char host[] = "nazv";
u_int prognum = 0x2000002F;
u_int versnum = 2;
char nettype[] = "tcp";

/*=============================*/
/*  main-program                                     */
/*=============================*/
int main (int argc, char *argv[])
{
int retval = 0;
int sleeptime = 0;
CLIENT *cl;     /* a client handle */

  // read sleep-Time
  if(argc < 2)
  {
    printf("no input for sleep-Time --> default\n");
    sleeptime = 10;
  }
  else
  {
    char *endptr;
    errno = 0;
    sleeptime = (int)strtol(argv[1], &endptr, 10);
    if ( (errno == ERANGE && (sleeptime == LONG_MAX || sleeptime == LONG_MIN))
         || (errno != 0 && sleeptime == 0))
    {
      fprintf(stderr, "input for sleeptime (%s) invalid: %s\n",
                      argv[1], strerror(errno));
      exit(1);
    }
  }

  printf("sleep-Time = %d \n", sleeptime);

  // loop for 20 connection
  for(int i=0; i<20; i++)
  {
    if(!(cl = clnt_create(host, prognum, versnum, nettype)))
    {
      // couldn't start client handle
      sprintf(local_errmsg, "%s: %s", host, clnt_spcreateerror("clnt_create"));
      retval = -1;
      break;
    }

    printf("connection nr. %d established \n", i+1);
    sleep(1);

    clnt_destroy(cl);
    printf("connection closed\n");

    printf("wait for %d sec.\n", sleeptime);
    sleep(sleeptime);

  };

  if(retval < 0)
    fprintf(stderr, "%s\n", local_errmsg);

  return(0);
} // end main()


Test 1: The program is started with argument "60" (sleep = 60 secs.)

Results:

Cygwin 1_5_18 (Windows XP, Windows 7)
The loop is completed without error (20 times the connection was opened and closed).

Cygwin 1_7_32 and 2_5_1 (Windows 7)
After the first connection is closed, a second connection in the loop is not possible (error message above) and the program exits.

RPC-Client on Linux (openSuSe Leap 42.1)
The loop is completed without error (20 times the connection was opened and closed).



Test 2: The program is started with argument "0" (sleep = 0 secs.)

Results:

Cygwin 1_5_18 (Windows XP, Windows 7)
The loop is completed without error (20 times the connection was opened and closed).

Cygwin 1_7_32 and 2_5_1 (Windows 7)
After the first connection is closed, a second connection in the loop is not possible (error message above) and the program exits.

RPC-Client on Linux (openSuSe Leap 42.1)
The loop is completed without error (20 times the connection was opened and closed).



Test 3: The program is started with argument "0" (sleep = 0 secs.)
Windows 7 only
Cygwin 1_7_32 and 2_5_1
After the program exited with the error, the program was immediately restarted. The start was ok (but always the program exited with the known error). But after several starts a new error was there:

Remote system error - Connection timed out


What is the reason for the error? I have to develop RPC-Clients for Windows XP SP3 and Windows 7.


Raimund Paulus