summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-10-24 00:55:18 +0000
committerNick Mathewson <nickm@torproject.org>2004-10-24 00:55:18 +0000
commit5d53828c57e35cf1fa0e1d0c0ebc03d70502f731 (patch)
treeaa9d0c89f1fa0acec80fe3368c53ca9280dd0965
parent78a2c3aa3973a745a1742b4cd0a5cb99f650cdf0 (diff)
downloadtor-5d53828c57e35cf1fa0e1d0c0ebc03d70502f731.tar.gz
tor-5d53828c57e35cf1fa0e1d0c0ebc03d70502f731.zip
Handle more errnos from accept() without closing the connection. This may fix a bug that could close OR listeners when (a) TCP connections were hung up before accept() could be called, or (b) during FD exhaustion.
svn:r2579
-rw-r--r--src/common/util.h10
-rw-r--r--src/or/connection.c10
2 files changed, 18 insertions, 2 deletions
diff --git a/src/common/util.h b/src/common/util.h
index 4d21f64bc1..e4f0eaec55 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -269,12 +269,22 @@ int parse_addr_and_port_range(const char *s, uint32_t *addr_out,
/** Return true if e is EINPROGRESS or the local equivalent as returned by
* a call to connect(). */
#define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == WSAEINPROGRESS || (e)== WSAEINVAL)
+/** Return true if e is EAGAIN or another error indicating that a call to
+ * accept() has no pending connections to return. */
+#define ERRNO_IS_ACCEPT_EAGAIN(e) ERRNO_IS_EAGAIN(e)
+/** Return true if e is EMFILE or another error indicating that a call to
+ * accept() has failed because we're out of fds or something. */
+#define ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e) \
+ ((e) == WSAEMFILE || (e) == WSAENOBUFS)
int tor_socket_errno(int sock);
const char *tor_socket_strerror(int e);
#else
#define ERRNO_IS_EAGAIN(e) ((e) == EAGAIN)
#define ERRNO_IS_EINPROGRESS(e) ((e) == EINPROGRESS)
#define ERRNO_IS_CONN_EINPROGRESS(e) ((e) == EINPROGRESS)
+#define ERRNO_IS_ACCEPT_EAGAIN(e) ((e) == EAGAIN || (e) == ECONNABORTED)
+#define ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e) \
+ ((e) == EMFILE || (e) == ENFILE || (e) == ENOBUFS || (e) == ENOMEM)
#define tor_socket_errno(sock) (errno)
#define tor_socket_strerror(e) strerror(e)
#endif
diff --git a/src/or/connection.c b/src/or/connection.c
index 477353b5f4..0c8b9f7424 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -385,11 +385,17 @@ static int connection_handle_listener_read(connection_t *conn, int new_type) {
news = accept(conn->s,(struct sockaddr *)&remote,&remotelen);
if (news == -1) { /* accept() error */
- if(ERRNO_IS_EAGAIN(tor_socket_errno(conn->s))) {
+ int e = tor_socket_errno(conn->s);
+ if (ERRNO_IS_ACCEPT_EAGAIN(e)) {
return 0; /* he hung up before we could accept(). that's fine. */
+ } else if (ERRNO_IS_ACCEPT_RESOURCE_LIMIT(e)) {
+ log_fn(LOG_WARN,"accept failed: %s. Dropping incomming connection.",
+ tor_socket_strerror(e));
+ return 0;
}
/* else there was a real error. */
- log_fn(LOG_WARN,"accept() failed. Closing listener.");
+ log_fn(LOG_WARN,"accept() failed: %s. Closing listener.",
+ tor_socket_strerror(e));
connection_mark_for_close(conn);
return -1;
}