mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-05-29 21:23:06 +00:00
zebra: don't send data after closing connection
Cancelling threads is nice but they can potentially be scheduled again after cancellation without an explicit check. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
parent
43ea2c7609
commit
ae6670d013
@ -53,6 +53,7 @@
|
|||||||
#include "lib/zassert.h" /* for assert */
|
#include "lib/zassert.h" /* for assert */
|
||||||
#include "lib/zclient.h" /* for zmsghdr, ZEBRA_HEADER_SIZE, ZEBRA... */
|
#include "lib/zclient.h" /* for zmsghdr, ZEBRA_HEADER_SIZE, ZEBRA... */
|
||||||
#include "lib/frr_pthread.h" /* for frr_pthread_new, frr_pthread_stop... */
|
#include "lib/frr_pthread.h" /* for frr_pthread_new, frr_pthread_stop... */
|
||||||
|
#include "lib/frratomic.h" /* for atomic_load_explicit, atomic_stor... */
|
||||||
|
|
||||||
#include "zebra/debug.h" /* for various debugging macros */
|
#include "zebra/debug.h" /* for various debugging macros */
|
||||||
#include "zebra/rib.h" /* for rib_score_proto */
|
#include "zebra/rib.h" /* for rib_score_proto */
|
||||||
@ -166,6 +167,7 @@ static void zserv_log_message(const char *errmsg, struct stream *msg,
|
|||||||
*/
|
*/
|
||||||
static void zserv_client_close(struct zserv *client)
|
static void zserv_client_close(struct zserv *client)
|
||||||
{
|
{
|
||||||
|
atomic_store_explicit(&client->dead, true, memory_order_seq_cst);
|
||||||
THREAD_OFF(client->t_read);
|
THREAD_OFF(client->t_read);
|
||||||
THREAD_OFF(client->t_write);
|
THREAD_OFF(client->t_write);
|
||||||
zserv_event(client, ZSERV_HANDLE_CLOSE);
|
zserv_event(client, ZSERV_HANDLE_CLOSE);
|
||||||
@ -199,6 +201,9 @@ static int zserv_write(struct thread *thread)
|
|||||||
int writerv;
|
int writerv;
|
||||||
struct stream_fifo *cache;
|
struct stream_fifo *cache;
|
||||||
|
|
||||||
|
if (atomic_load_explicit(&client->dead, memory_order_seq_cst))
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* If we have any data pending, try to flush it first */
|
/* If we have any data pending, try to flush it first */
|
||||||
switch (buffer_flush_available(client->wb, client->sock)) {
|
switch (buffer_flush_available(client->wb, client->sock)) {
|
||||||
case BUFFER_ERROR:
|
case BUFFER_ERROR:
|
||||||
@ -286,18 +291,23 @@ zwrite_fail:
|
|||||||
*/
|
*/
|
||||||
static int zserv_read(struct thread *thread)
|
static int zserv_read(struct thread *thread)
|
||||||
{
|
{
|
||||||
|
struct zserv *client = THREAD_ARG(thread);
|
||||||
int sock;
|
int sock;
|
||||||
struct zserv *client;
|
|
||||||
size_t already;
|
size_t already;
|
||||||
struct stream_fifo *cache = stream_fifo_new();
|
struct stream_fifo *cache;
|
||||||
uint32_t p2p_orig = atomic_load_explicit(&zebrad.packets_to_process,
|
uint32_t p2p_orig;
|
||||||
memory_order_relaxed);
|
|
||||||
uint32_t p2p;
|
uint32_t p2p;
|
||||||
struct zmsghdr hdr;
|
struct zmsghdr hdr;
|
||||||
|
|
||||||
|
if (atomic_load_explicit(&client->dead, memory_order_seq_cst))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
p2p_orig = atomic_load_explicit(&zebrad.packets_to_process,
|
||||||
|
memory_order_relaxed);
|
||||||
|
cache = stream_fifo_new();
|
||||||
p2p = p2p_orig;
|
p2p = p2p_orig;
|
||||||
sock = THREAD_FD(thread);
|
sock = THREAD_FD(thread);
|
||||||
client = THREAD_ARG(thread);
|
|
||||||
|
|
||||||
while (p2p) {
|
while (p2p) {
|
||||||
ssize_t nb;
|
ssize_t nb;
|
||||||
@ -435,6 +445,9 @@ zread_fail:
|
|||||||
static void zserv_client_event(struct zserv *client,
|
static void zserv_client_event(struct zserv *client,
|
||||||
enum zserv_client_event event)
|
enum zserv_client_event event)
|
||||||
{
|
{
|
||||||
|
if (atomic_load_explicit(&client->dead, memory_order_seq_cst))
|
||||||
|
return;
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case ZSERV_CLIENT_READ:
|
case ZSERV_CLIENT_READ:
|
||||||
thread_add_read(client->pthread->master, zserv_read, client,
|
thread_add_read(client->pthread->master, zserv_read, client,
|
||||||
|
@ -53,6 +53,9 @@ struct zserv {
|
|||||||
/* Client pthread */
|
/* Client pthread */
|
||||||
struct frr_pthread *pthread;
|
struct frr_pthread *pthread;
|
||||||
|
|
||||||
|
/* Whether the thread is waiting to be killed */
|
||||||
|
_Atomic bool dead;
|
||||||
|
|
||||||
/* Client file descriptor. */
|
/* Client file descriptor. */
|
||||||
int sock;
|
int sock;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user