From 873d6fa3e18985934448728b42f04c733e74a896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= Date: Wed, 14 Jun 2017 18:24:53 +0100 Subject: [PATCH] Handle backend unsolicited response properly --- servers/lloadd/upstream.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/servers/lloadd/upstream.c b/servers/lloadd/upstream.c index 54d6944256..c9156782de 100644 --- a/servers/lloadd/upstream.c +++ b/servers/lloadd/upstream.c @@ -271,25 +271,13 @@ done: static int handle_unsolicited( Connection *c, BerElement *ber ) { - TAvlnode *root; - long freed, executing; + c->c_state = SLAP_C_CLOSING; Debug( LDAP_DEBUG_CONNS, "handle_unsolicited: " "teardown for upstream connection %lu\n", c->c_connid ); - root = c->c_ops; - c->c_ops = NULL; - executing = c->c_n_ops_executing; - CONNECTION_UNLOCK_INCREF(c); - - freed = tavl_free( root, (AVL_FREE)operation_lost_upstream ); - assert( freed == executing ); - Debug( LDAP_DEBUG_TRACE, "handle_unsolicited: " - "dropped %ld operations\n", - freed ); - - UPSTREAM_LOCK_DESTROY(c); + UPSTREAM_DESTROY(c); ber_free( ber, 1 ); return -1; @@ -902,7 +890,7 @@ upstream_destroy( Connection *c ) Backend *b = c->c_private; struct event *read_event, *write_event; TAvlnode *root; - long freed; + long freed, executing; Debug( LDAP_DEBUG_CONNS, "upstream_destroy: " "freeing connection %lu\n", @@ -912,12 +900,14 @@ upstream_destroy( Connection *c ) root = c->c_ops; c->c_ops = NULL; + executing = c->c_n_ops_executing; read_event = c->c_read_event; write_event = c->c_write_event; CONNECTION_UNLOCK_INCREF(c); freed = tavl_free( root, (AVL_FREE)operation_lost_upstream ); + assert( freed == executing ); /* * Avoid a deadlock: @@ -940,7 +930,7 @@ upstream_destroy( Connection *c ) LDAP_CIRCLEQ_REMOVE( &b->b_conns, c, c_next ); b->b_active--; } - b->b_n_ops_executing -= c->c_n_ops_executing; + b->b_n_ops_executing -= executing; ldap_pvt_thread_mutex_unlock( &b->b_mutex ); backend_retry( b );