From: Jonathan Rajotte Date: Tue, 20 Dec 2016 23:25:17 +0000 (-0500) Subject: Fix: lttng-relayd: forcefully close stream on relayd shutdown X-Git-Tag: v2.10.0-rc1~79 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=98ba050ed140ff29ac98f66dba0e47db70e4a0c5;p=lttng-tools.git Fix: lttng-relayd: forcefully close stream on relayd shutdown Add an "aborted" field to relay_session struct to indicate that on shutdown pending data for a stream is no relevant and should not be waited for. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index dc19a69c7..7b313818e 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -2680,6 +2680,11 @@ error: destroy_conn, sock_n.node) { health_code_update(); + + if (session_abort(destroy_conn->session)) { + assert(0); + } + /* * No need to grab another ref, because we own * destroy_conn. diff --git a/src/bin/lttng-relayd/session.c b/src/bin/lttng-relayd/session.c index 9702bd220..f76fb4a42 100644 --- a/src/bin/lttng-relayd/session.c +++ b/src/bin/lttng-relayd/session.c @@ -228,6 +228,27 @@ rcu_unlock: return ret; } +int session_abort(struct relay_session *session) +{ + int ret = 0; + + if (!session) { + return 0; + } + + pthread_mutex_lock(&session->lock); + DBG("aborting session %" PRIu64, session->id); + if (session->aborted) { + ERR("session %" PRIu64 " is already aborted", session->id); + ret = -1; + goto unlock; + } + session->aborted = true; +unlock: + pthread_mutex_unlock(&session->lock); + return ret; +} + void print_sessions(void) { struct lttng_ht_iter iter; diff --git a/src/bin/lttng-relayd/session.h b/src/bin/lttng-relayd/session.h index 3ee1c45c3..4c8f8a61f 100644 --- a/src/bin/lttng-relayd/session.h +++ b/src/bin/lttng-relayd/session.h @@ -67,6 +67,13 @@ struct relay_session { /* Tell if the session connection has been closed on the streaming side. */ bool connection_closed; + /* + * Tell if the session is currently living in a exiting relayd and + * should be cleaned forcefully without waiting for pending data or + * pending ctrl data. + */ + bool aborted; + /* Contains ctf_trace object of that session indexed by path name. */ struct lttng_ht *ctf_traces_ht; @@ -111,6 +118,8 @@ bool session_get(struct relay_session *session); void session_put(struct relay_session *session); int session_close(struct relay_session *session); +int session_abort(struct relay_session *session); + void print_sessions(void); #endif /* _SESSION_H */ diff --git a/src/bin/lttng-relayd/stream.c b/src/bin/lttng-relayd/stream.c index c59bb9416..e9c7ad172 100644 --- a/src/bin/lttng-relayd/stream.c +++ b/src/bin/lttng-relayd/stream.c @@ -345,7 +345,15 @@ void stream_put(struct relay_stream *stream) void try_stream_close(struct relay_stream *stream) { + bool session_aborted; + struct relay_session *session = stream->trace->session; + DBG("Trying to close stream %" PRIu64, stream->stream_handle); + + pthread_mutex_lock(&session->lock); + session_aborted = session->aborted; + pthread_mutex_unlock(&session->lock); + pthread_mutex_lock(&stream->lock); /* * Can be called concurently by connection close and reception of last @@ -387,7 +395,8 @@ void try_stream_close(struct relay_stream *stream) } if (stream->last_net_seq_num != -1ULL && - ((int64_t) (stream->prev_seq - stream->last_net_seq_num)) < 0) { + ((int64_t) (stream->prev_seq - stream->last_net_seq_num)) < 0 + && !session_aborted) { /* * Don't close since we still have data pending. This * handles cases where an explicit close command has