summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3a61ffc)
raw | patch | inline | side by side (parent: 3a61ffc)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 10 Apr 2014 20:15:03 +0000 (22:15 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 10 Apr 2014 20:15:03 +0000 (22:15 +0200) |
Make sure not to write to a failed connection, most notably, don't try to log
to a failed connection.
to a failed connection.
src/frontend/connection.c | patch | blob | history | |
src/frontend/sock.c | patch | blob | history |
index 12812c7132b20e35da6954757ddbcb5f6f2e7a7d..69c71edbd3e6f7ac9e5876841d9237f738267ab5 100644 (file)
sdb_log(SDB_LOG_DEBUG, "frontend: Closing connection on fd=%i",
conn->fd);
- close(conn->fd);
+ if (conn->fd >= 0)
+ close(conn->fd);
conn->fd = -1;
sdb_strbuf_destroy(conn->buf);
{
ssize_t n = 0;
+ if ((! conn) || (conn->fd < 0))
+ return -1;
+
while (42) {
ssize_t status;
if (status < 0) {
if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
break;
+
+ close(conn->fd);
+ conn->fd = -1;
return (int)status;
}
else if (! status) /* EOF */
if (status < 0) {
char errbuf[1024];
+ /* tell other code that there was a problem and, more importantly,
+ * make sure we don't try to send further logs to the connection */
+ close(conn->fd);
+ conn->fd = -1;
+
sdb_log(SDB_LOG_ERR, "frontend: Failed to send msg "
"(code: %u, len: %u) to client: %s", code, msg_len,
sdb_strerror(errno, errbuf, sizeof(errbuf)));
diff --git a/src/frontend/sock.c b/src/frontend/sock.c
index 70f22d705b694a4e24b6ff0639cd4cd33e0f4932..7cfdb7cac4b84d21c2f476e38b08855ea80c970b 100644 (file)
--- a/src/frontend/sock.c
+++ b/src/frontend/sock.c
while (sdb_llist_iter_has_next(iter)) {
sdb_object_t *obj = sdb_llist_iter_get_next(iter);
+
+ if (CONN(obj)->fd < 0) {
+ sdb_llist_iter_remove_current(iter);
+ sdb_object_deref(obj);
+ continue;
+ }
+
FD_SET(CONN(obj)->fd, &ready);
FD_SET(CONN(obj)->fd, &exceptions);