From f832024e90007fd71b516b81a00bc5608df45b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= Date: Fri, 5 Oct 2018 14:56:19 +0100 Subject: [PATCH] Straighten up client pending op tracking --- servers/lloadd/bind.c | 10 ++++++++++ servers/lloadd/client.c | 7 +++++-- servers/lloadd/extended.c | 5 ++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/servers/lloadd/bind.c b/servers/lloadd/bind.c index 4f429602f9..537ea093c0 100644 --- a/servers/lloadd/bind.c +++ b/servers/lloadd/bind.c @@ -244,6 +244,7 @@ request_bind( LloadConnection *client, LloadOperation *op ) } tavl_delete( &client->c_ops, op, operation_client_cmp ); + client->c_n_ops_executing--; client_reset( client ); @@ -326,6 +327,7 @@ request_bind( LloadConnection *client, LloadOperation *op ) rc = tavl_insert( &client->c_ops, op, operation_client_cmp, avl_dup_error ); assert( rc == LDAP_SUCCESS ); + client->c_n_ops_executing++; CONNECTION_UNLOCK(client); if ( pin ) { @@ -663,6 +665,7 @@ handle_bind_response( assert( !removed || op == removed ); if ( client->c_state == LLOAD_C_BINDING ) { + assert( removed ); switch ( result ) { case LDAP_SASL_BIND_IN_PROGRESS: op->o_saved_msgid = op->o_client_msgid; @@ -676,6 +679,7 @@ handle_bind_response( client->c_state = LLOAD_C_READY; client->c_type = LLOAD_C_OPEN; client->c_pin_id = 0; + client->c_n_ops_executing--; if ( !BER_BVISNULL( &client->c_auth ) ) { if ( result != LDAP_SUCCESS ) { ber_memfree( client->c_auth.bv_val ); @@ -693,6 +697,9 @@ handle_bind_response( } } } else { + if ( removed ) { + client->c_n_ops_executing--; + } assert( client->c_state == LLOAD_C_DYING || client->c_state == LLOAD_C_CLOSING ); } @@ -783,6 +790,9 @@ handle_whoami_response( removed = tavl_delete( &client->c_ops, op, operation_client_cmp ); assert( !removed || op == removed ); op->o_pin_id = 0; + if ( removed ) { + client->c_n_ops_executing--; + } Debug( LDAP_DEBUG_TRACE, "handle_whoami_response: " "connid=%ld new authid=%s\n", diff --git a/servers/lloadd/client.c b/servers/lloadd/client.c index f03810a3b0..64f77beba6 100644 --- a/servers/lloadd/client.c +++ b/servers/lloadd/client.c @@ -445,9 +445,12 @@ void client_reset( LloadConnection *c ) { TAvlnode *root; + long freed = 0, executing; root = c->c_ops; c->c_ops = NULL; + executing = c->c_n_ops_executing; + c->c_n_ops_executing = 0; if ( !BER_BVISNULL( &c->c_auth ) ) { ch_free( c->c_auth.bv_val ); @@ -460,12 +463,12 @@ client_reset( LloadConnection *c ) CONNECTION_UNLOCK(c); if ( root ) { - int freed; freed = tavl_free( root, (AVL_FREE)operation_abandon ); Debug( LDAP_DEBUG_TRACE, "client_reset: " - "dropped %d operations\n", + "dropped %ld operations\n", freed ); } + assert( freed == executing ); CONNECTION_LOCK(c); } diff --git a/servers/lloadd/extended.c b/servers/lloadd/extended.c index 1f22a71968..d7775fff4c 100644 --- a/servers/lloadd/extended.c +++ b/servers/lloadd/extended.c @@ -32,12 +32,15 @@ int handle_starttls( LloadConnection *c, LloadOperation *op ) { struct event_base *base = event_get_base( c->c_read_event ); + LloadOperation *found; BerElement *output; char *msg = NULL; int rc = LDAP_SUCCESS; CONNECTION_LOCK(c); - tavl_delete( &c->c_ops, op, operation_client_cmp ); + found = tavl_delete( &c->c_ops, op, operation_client_cmp ); + assert( op == found ); + c->c_n_ops_executing--; if ( c->c_is_tls == LLOAD_TLS_ESTABLISHED ) { rc = LDAP_OPERATIONS_ERROR;