summaryrefslogtreecommitdiff
path: root/src/feature
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2021-01-27 09:34:34 -0500
committerNick Mathewson <nickm@torproject.org>2021-02-08 14:26:45 -0500
commit01c4abc2d41a7d140a0c0931528fc680dcbac0ee (patch)
tree3d3eb1c42f7370f18af1f9e738976d5f960a76ad /src/feature
parentf420eacf1858220f1cb284353f975e03464b15e4 (diff)
downloadtor-01c4abc2d41a7d140a0c0931528fc680dcbac0ee.tar.gz
tor-01c4abc2d41a7d140a0c0931528fc680dcbac0ee.zip
conn: Properly close MetricsPort socket on EOF
Handle the EOF situation for a metrics connection. Furthermore, if we failed to fetch the data from the inbuf properly, mark the socket as closed because the caller, connection_process_inbuf(), assumes that we did so on error. Fixes #40257 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature')
-rw-r--r--src/feature/metrics/metrics.c21
-rw-r--r--src/feature/metrics/metrics.h1
2 files changed, 19 insertions, 3 deletions
diff --git a/src/feature/metrics/metrics.c b/src/feature/metrics/metrics.c
index 886182bc90..7a77ab1104 100644
--- a/src/feature/metrics/metrics.c
+++ b/src/feature/metrics/metrics.c
@@ -20,6 +20,7 @@
#include "lib/net/address.h"
#include "core/mainloop/connection.h"
+#include "core/or/connection_or.h"
#include "core/or/connection_st.h"
#include "core/or/policies.h"
#include "core/or/port_cfg_st.h"
@@ -93,7 +94,8 @@ metrics_get_output(const metrics_format_t fmt)
/** Process what is in the inbuf of this connection of type metrics.
*
- * Return 0 on success else -1 on error which will close the connection. */
+ * Return 0 on success else -1 on error for which the connection is marked for
+ * close. */
int
metrics_connection_process_inbuf(connection_t *conn)
{
@@ -111,13 +113,14 @@ metrics_connection_process_inbuf(connection_t *conn)
goto err;
}
- const int http_status = fetch_from_buf_http(conn->inbuf, &headers, 1024,
- NULL, NULL, 1024, 0);
+ const int http_status =
+ connection_fetch_from_buf_http(conn, &headers, 1024, NULL, NULL, 1024, 0);
if (http_status < 0) {
errmsg = "HTTP/1.0 400 Bad Request\r\n\r\n";
goto err;
} else if (http_status == 0) {
/* no HTTP request yet. */
+ ret = 0;
goto done;
}
@@ -155,6 +158,7 @@ metrics_connection_process_inbuf(connection_t *conn)
log_info(LD_EDGE, "HTTP metrics error: saying %s", escaped(errmsg));
connection_buf_add(errmsg, strlen(errmsg), conn);
}
+ connection_mark_and_flush(conn);
done:
tor_free(headers);
@@ -243,6 +247,17 @@ metrics_parse_ports(or_options_t *options, smartlist_t *ports,
return ret;
}
+/** Called when conn has gotten its socket closed. */
+int
+metrics_connection_reached_eof(connection_t *conn)
+{
+ tor_assert(conn);
+
+ log_info(LD_EDGE, "Metrics connection reached EOF. Closing.");
+ connection_mark_for_close(conn);
+ return 0;
+}
+
/** Initialize the subsystem. */
void
metrics_init(void)
diff --git a/src/feature/metrics/metrics.h b/src/feature/metrics/metrics.h
index b4bbe28b27..858722de59 100644
--- a/src/feature/metrics/metrics.h
+++ b/src/feature/metrics/metrics.h
@@ -27,6 +27,7 @@ buf_t *metrics_get_output(const metrics_format_t fmt);
/* Connection. */
int metrics_connection_process_inbuf(struct connection_t *conn);
+int metrics_connection_reached_eof(struct connection_t *conn);
/* Configuration. */
int metrics_parse_ports(or_options_t *options, smartlist_t *ports,