Advertisement
Snuggledash

Gatling EMFILE patches

Nov 29th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.05 KB | Source Code | 0 0
  1. diff -u -r1.322 -r1.324
  2. --- gatling.c   20 Jul 2023 09:18:52 -0000  1.322
  3. +++ gatling.c   21 Nov 2024 16:06:23 -0000  1.324
  4. @@ -580,6 +580,8 @@
  5.  
  6.  int limit_to_lan;
  7.  
  8. +int dummy_fd_for_EMFILE;
  9. +
  10.  static void accept_server_connection(int64 i,struct http_data* H,unsigned long ftptimeout_secs,tai6464 nextftp) {
  11.    /* This is an FTP or HTTP(S) or SMB server connection.
  12.      * This read event means that someone connected to us.
  13. @@ -593,6 +595,7 @@
  14.  
  15.    while (1) {
  16.      int punk;
  17. +emfile_emergency:
  18.  #ifdef __broken_itojun_v6__
  19.      if (H->t==HTTPSERVER4 || H->t==FTPSERVER4
  20.  #ifdef SUPPORT_SMB
  21. @@ -608,6 +611,36 @@
  22.      } else
  23.  #endif
  24.        n=socket_accept6(i,ip,&port,&scope_id);
  25. +    if (n==-1 && errno==EMFILE) {
  26. +      /* This is an exceptional situation. We ran into the limit on open
  27. +       * file descriptors. If we just do nothing, we'll create an
  28. +       * infinite loop because libowfat will just continue reporting the
  29. +       * same fd over and over. But we can't drop the connection attempt
  30. +       * without having accept succeed and then calling close on the new
  31. +       * fd in the socket API. So we kept a dummy fd around for this
  32. +       * occasion. */
  33. +      if (dummy_fd_for_EMFILE==-1) {
  34. +   buffer_putsflush(buffer_1,"EMFILE emergency close didn't work!\n");
  35. +   exit(111);
  36. +      }
  37. +      close(dummy_fd_for_EMFILE);
  38. +      dummy_fd_for_EMFILE=-1;
  39. +      goto emfile_emergency;
  40. +    }
  41. +    if (dummy_fd_for_EMFILE==-1) {
  42. +      if (n!=-1) {
  43. +   buffer_puts(buffer_1,"close/emfile ");
  44. +   buffer_putulong(buffer_1,n);
  45. +   buffer_putnlflush(buffer_1);
  46. +   close(n);   // we just made space for an fd, so the accept
  47. +      }
  48. +           // should have gone through.
  49. +      dummy_fd_for_EMFILE=dup(0);
  50. +      if (dummy_fd_for_EMFILE==-1) {
  51. +   buffer_putsflush(buffer_1,"EMFILE emergency dup failed!\n");
  52. +   exit(111);
  53. +      }
  54. +    }
  55.      if (n==-1) break;
  56.      punk=new_request_from_ip(ip,Now)==1;
  57.      ++cps1;
  58. @@ -1533,6 +1566,12 @@
  59.    pid_t* Instances;
  60.  #endif
  61.  
  62. +  dummy_fd_for_EMFILE=dup(0);
  63. +  if (dummy_fd_for_EMFILE==-1) {
  64. +    perror("dup");
  65. +    exit(111);
  66. +  }
  67. +
  68.    initdircache();
  69.    maxlngdelta=1;
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement