title: net_ratelimit message in kernel log when creating multiple TCP connection in NONBLOCKING mode
body: <p>I've a C program which tries to poll for devices in network and if the devices are available it tries read value from them. But when no devices are present running of the application creates following message in kernel log. Also there is no other warning/alert messages in the log than the below message. (Even after disabling ratelimit using <code>net.core.message_cost=0</code>)</p>
  
  <pre><code>net_ratelimit: xx callbacks supressed
  </code></pre>
  
  <p>And at the same time another application which broadcasts messages over network starts to fail in the send system call returning <code>EINVAL</code>. Once I stop the polling <code>TCP</code> client the <code>UDP Broadcast</code> application runs fine.</p>
  
  <p>The system where I run this is a <code>RAMFS</code> based system running <strong>3.14 series kernel</strong> with <code>RT_PREEMPT</code> <strong>patch applied</strong>. I've written a sample application for which mimics same behavior as my original application when I start 5 process in background. (note that its more than 4 process which triggers it). Below is sample client code.</p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/select.h&gt;
  #include &lt;sys/time.h&gt;
  #include &lt;sys/ioctl.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;netinet/in.h&gt;
  
  #include &lt;unistd.h&gt;
  #include &lt;errno.h&gt;
  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  #define CHK_NULL(x) if ((x)==NULL) exit (1)
  #define CHK_ERR(err,s) if ((err)==-1) { perror(s); exit(1); }
  #define CHK_SSL(err) if ((err)==-1) { ERR_print_errors_fp(stderr); exit(2); }
  
  int sfd;
  
  void openProtocol(const char *hostname) {
       int sfd = socket(PF_INET, SOCK_STREAM, 0);
       CHK_ERR(sfd, "socket");
  
       struct sockaddr_in address;
       memset(&amp;address, 0, sizeof(address));
       address.sin_family = PF_INET;
       address.sin_addr.s_addr = inet_addr(hostname);
       address.sin_port = htons(502);
  
       int opt = 1;
       int result = ioctl(sfd, FIONBIO, &amp;opt);
       if (result == -1) {
        close(sfd);
        CHK_ERR(result, "ioctl");
       }
  
       result = connect(sfd, (struct sockaddr*)&amp;address, sizeof(address));
       if (result == -1 &amp;&amp; errno != EINPROGRESS) {
        close(sfd);
        CHK_ERR(result, "connect");
       }
  
       fd_set fdlist;
       FD_ZERO(&amp;fdlist);
       struct timeval tm;
       tm.tv_sec = 1;
       tm.tv_usec = 0;
  
       result = select(sfd + 1, NULL, &amp;fdlist, NULL, &amp;tm);
       if (result == 0) {
        printf ("TCP/IP connection error!\n");
        close(sfd);
       }
  
       if (result == -1) {
        close(sfd);
        CHK_ERR(result, "select");
       }
  }
  
  int main(int argc, char *argv[])
  {
       char *base_addr = "192.168.1.";
       unsigned short startAddr = 21;
  
       if ( argc &lt; 3) {
        fprintf (stderr, "Please provide number of IP and wait period\n");
        exit(EXIT_FAILURE);
       }
  
       unsigned int no_of_ip;
       if (sscanf (argv[1], "%u", (unsigned int*)&amp;no_of_ip) != 1 ) {
        fprintf (stderr, "Scan of number of device failed\n");
        exit(EXIT_FAILURE);
       }
  
       unsigned int wait_period;
       if (sscanf (argv[2], "%u", (unsigned int*)&amp;wait_period) != 1) {
        fprintf (stderr, "Scan of wait period failed\n");
        exit(EXIT_FAILURE);
       }
  
       char full_addr[100];
       char last_part[10];
       while (1) {
        for (int i = startAddr; i &lt; (startAddr + no_of_ip); i++) {
             memset(&amp;full_addr[0], 0, sizeof(full_addr));
             memset(&amp;last_part[0], 0, sizeof(last_part));
             strncat (full_addr, base_addr, sizeof(full_addr));
             snprintf (last_part, sizeof(last_part), "%u", i);
             strncat (full_addr, last_part, sizeof(full_addr));
  
             openProtocol(full_addr);
             usleep(wait_period * 1000);
        }   
       }
  
       return 0;
  }
  </code></pre>
  
  <p>Application takes input as number of devices and wait time. I run 5 instances of above application via a shell script with <strong><code>128</code> as device number</strong> and <code>5</code> as wait time (<strong>5 ms</strong>).</p>
  
  <p>Now my question.</p>
  
  <ol>
  <li><p>Why am I getting the <code>net_ratelimit</code> messages when running this application (<strong><code>5</code> instances</strong>). I tried disabling <code>net_ratelimit</code> by setting <code>net.core.message_cost</code> to <code>0</code> but I can't find anything in the kernel log other than the <code>net_ratelimit</code> messages.</p></li>
  <li><p>Why is an unrelated application (<code>UDP broadcast</code> client) is getting <code>EINVAL</code> when trying to send the broadcast. Also this happens only when my polling application runs. Killing polling application the broadcast client returns to normal.</p></li>
  </ol>
  
  <p>PS: I could not get a better title line, if some one has better title line please suggest/edit ;-).</p>