r17095 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17094‎ | r17095 | r17096 >
Date:21:21, 18 October 2006
Author:river
Status:old
Tags:
Comment:
rate-limit errors caused by ENFILE so we don't flood the log when running out of fds
Modified paths:
  • /trunk/willow/src/willow/wbackend.cc (modified) (history)
  • /trunk/willow/src/willow/wnet.cc (modified) (history)

Diff [purge]

Index: trunk/willow/src/willow/wnet.cc
@@ -121,20 +121,27 @@
122122 #endif
123123 int newfd, val;
124124 struct fde *newe;
125 -
 125+static time_t last_nfile = 0;
 126+ time_t now = time(NULL);
126127 if ((cdata = (client_data *)wcalloc(1, sizeof(*cdata))) == NULL)
127128 outofmemory();
128129
129130 addrlen = sizeof(cdata->cdat_addr);
130131
131132 if ((newfd = accept(e->fde_fd, (struct sockaddr *) &cdata->cdat_addr, &addrlen)) < 0) {
132 - wlog(WLOG_NOTICE, "accept error: %s", strerror(errno));
 133+ if (errno != ENFILE || now - last_nfile > 60)
 134+ wlog(WLOG_NOTICE, "accept error: %s", strerror(errno));
 135+ if (errno == ENFILE)
 136+ last_nfile = now;
133137 wfree(cdata);
134138 return;
135139 }
136140
137141 if (newfd >= max_fd) {
138 - wlog(WLOG_NOTICE, "out of file descriptors!");
 142+ if (errno != ENFILE || now - last_nfile > 60)
 143+ wlog(WLOG_NOTICE, "out of file descriptors!");
 144+ if (errno == ENFILE)
 145+ last_nfile = now;
139146 wfree(cdata);
140147 (void)close(newfd);
141148 return;
@@ -173,9 +180,13 @@
174181 wnet_open(const char *desc)
175182 {
176183 int fd, val;
177 -
 184+static int last_nfile = 0;
 185+ time_t now = time(NULL);
178186 if ((fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
179 - wlog(WLOG_WARNING, "socket: %s", strerror(errno));
 187+ if (errno != ENFILE || now - last_nfile > 60)
 188+ wlog(WLOG_WARNING, "socket: %s", strerror(errno));
 189+ if (errno == ENFILE)
 190+ last_nfile = now;
180191 return -1;
181192 }
182193
Index: trunk/willow/src/willow/wbackend.cc
@@ -96,7 +96,9 @@
9797 {
9898 struct backend_cb_data *cbd;
9999 int s;
100 -
 100+static time_t last_nfile;
 101+ time_t now = time(NULL);
 102+
101103 WDEBUG((WLOG_DEBUG, "get_backend: called"));
102104
103105 cbd = new backend_cb_data;
@@ -114,7 +116,10 @@
115117 }
116118
117119 if ((s = wnet_open("backend connection")) == -1) {
118 - wlog(WLOG_WARNING, "opening backend socket: %s", strerror(errno));
 120+ if (errno != ENFILE || now - last_nfile > 60)
 121+ wlog(WLOG_WARNING, "opening backend socket: %s", strerror(errno));
 122+ if (errno == ENFILE)
 123+ last_nfile = now;
119124 wfree(cbd);
120125 return -1;
121126 }