From 85b11787da6413eed6b25595c462ebb3f0500df2 Mon Sep 17 00:00:00 2001 From: eido5 Date: Mon, 21 Nov 2022 17:00:05 +0900 Subject: [PATCH 1/7] [APIS-945] Fix the core dump error related with CCI Connection Pool --- src/cci/cas_cci.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/cci/cas_cci.c b/src/cci/cas_cci.c index 72af374..a99b601 100644 --- a/src/cci/cas_cci.c +++ b/src/cci/cas_cci.c @@ -675,6 +675,7 @@ int cci_disconnect (int mapped_conn_id, T_CCI_ERROR * err_buf) { int error = CCI_ER_NO_ERROR; + int rv; T_CON_HANDLE *con_handle = NULL; #ifdef CCI_DEBUG @@ -712,14 +713,24 @@ cci_disconnect (int mapped_conn_id, T_CCI_ERROR * err_buf) get_last_error (con_handle, err_buf); } - else if (con_handle->broker_info[BROKER_INFO_CCI_PCONNECT] && hm_put_con_to_pool (con_handle->id) >= 0) + else if (con_handle->broker_info[BROKER_INFO_CCI_PCONNECT]) { - cci_end_tran_internal (con_handle, CCI_TRAN_ROLLBACK); - API_ELOG (con_handle, 0); + if (con_handle->id < 0) + { + return CCI_ER_INVALID_ARGS; + } + MUTEX_LOCK (con_handle_table_mutex); + rv = hm_put_con_to_pool (con_handle->id); + MUTEX_UNLOCK (con_handle_table_mutex); + if (rv >= 0) + { + cci_end_tran_internal (con_handle, CCI_TRAN_ROLLBACK); + API_ELOG (con_handle, 0); - get_last_error (con_handle, err_buf); - con_handle->used = false; - hm_release_connection (mapped_conn_id, &con_handle); + get_last_error (con_handle, err_buf); + con_handle->used = false; + hm_release_connection (mapped_conn_id, &con_handle); + } } else { From 91799534ed511c25a5f11f3f4ea5762ef40cc9b9 Mon Sep 17 00:00:00 2001 From: eido5 Date: Tue, 22 Nov 2022 15:21:40 +0900 Subject: [PATCH 2/7] Change the function flow --- src/cci/cas_cci.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/cci/cas_cci.c b/src/cci/cas_cci.c index a99b601..21653bc 100644 --- a/src/cci/cas_cci.c +++ b/src/cci/cas_cci.c @@ -694,6 +694,20 @@ cci_disconnect (int mapped_conn_id, T_CCI_ERROR * err_buf) API_SLOG (con_handle); + if (con_handle->broker_info[BROKER_INFO_CCI_PCONNECT]) + { + if (con_handle->id >= 0) + { + MUTEX_LOCK (con_handle_table_mutex); + rv = hm_put_con_to_pool (con_handle->id); + MUTEX_UNLOCK (con_handle_table_mutex); + } + else + { + rv = -1; + } + } + if (con_handle->datasource) { con_handle->used = false; @@ -713,24 +727,14 @@ cci_disconnect (int mapped_conn_id, T_CCI_ERROR * err_buf) get_last_error (con_handle, err_buf); } - else if (con_handle->broker_info[BROKER_INFO_CCI_PCONNECT]) + else if (con_handle->broker_info[BROKER_INFO_CCI_PCONNECT] && rv >= 0) { - if (con_handle->id < 0) - { - return CCI_ER_INVALID_ARGS; - } - MUTEX_LOCK (con_handle_table_mutex); - rv = hm_put_con_to_pool (con_handle->id); - MUTEX_UNLOCK (con_handle_table_mutex); - if (rv >= 0) - { - cci_end_tran_internal (con_handle, CCI_TRAN_ROLLBACK); - API_ELOG (con_handle, 0); + cci_end_tran_internal (con_handle, CCI_TRAN_ROLLBACK); + API_ELOG (con_handle, 0); - get_last_error (con_handle, err_buf); - con_handle->used = false; - hm_release_connection (mapped_conn_id, &con_handle); - } + get_last_error (con_handle, err_buf); + con_handle->used = false; + hm_release_connection (mapped_conn_id, &con_handle); } else { From a4581adec02f362685c0df66c47cd4727510692f Mon Sep 17 00:00:00 2001 From: eido5 Date: Sat, 26 Nov 2022 12:21:30 +0900 Subject: [PATCH 3/7] Change the function flow --- src/cci/cas_cci.c | 38 +++++++++++++++++++------------------- src/cci/cci_handle_mng.c | 11 +++++++++++ src/cci/cci_handle_mng.h | 1 + 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/cci/cas_cci.c b/src/cci/cas_cci.c index 21653bc..5dc67e6 100644 --- a/src/cci/cas_cci.c +++ b/src/cci/cas_cci.c @@ -675,7 +675,6 @@ int cci_disconnect (int mapped_conn_id, T_CCI_ERROR * err_buf) { int error = CCI_ER_NO_ERROR; - int rv; T_CON_HANDLE *con_handle = NULL; #ifdef CCI_DEBUG @@ -694,20 +693,6 @@ cci_disconnect (int mapped_conn_id, T_CCI_ERROR * err_buf) API_SLOG (con_handle); - if (con_handle->broker_info[BROKER_INFO_CCI_PCONNECT]) - { - if (con_handle->id >= 0) - { - MUTEX_LOCK (con_handle_table_mutex); - rv = hm_put_con_to_pool (con_handle->id); - MUTEX_UNLOCK (con_handle_table_mutex); - } - else - { - rv = -1; - } - } - if (con_handle->datasource) { con_handle->used = false; @@ -727,14 +712,29 @@ cci_disconnect (int mapped_conn_id, T_CCI_ERROR * err_buf) get_last_error (con_handle, err_buf); } - else if (con_handle->broker_info[BROKER_INFO_CCI_PCONNECT] && rv >= 0) + else if (con_handle->broker_info[BROKER_INFO_CCI_PCONNECT] && hm_put_con_to_pool_exceed () == 0) { - cci_end_tran_internal (con_handle, CCI_TRAN_ROLLBACK); - API_ELOG (con_handle, 0); + MUTEX_LOCK (con_handle_table_mutex); + if (con_handle->id < 0 || hm_put_con_to_pool (con_handle->id) < 0) + { + qe_con_close (con_handle); + + error = CCI_ER_BIND_INDEX; + API_ELOG (con_handle, error); + reset_error_buffer (&(con_handle->err_buf)); + set_error_buffer (&(con_handle->err_buf), error, NULL); + hm_delete_connection (mapped_conn_id, &con_handle); + } + else + { + API_ELOG (con_handle, 0); + cci_end_tran_internal (con_handle, CCI_TRAN_ROLLBACK); + hm_release_connection (mapped_conn_id, &con_handle); + } get_last_error (con_handle, err_buf); con_handle->used = false; - hm_release_connection (mapped_conn_id, &con_handle); + MUTEX_UNLOCK (con_handle_table_mutex); } else { diff --git a/src/cci/cci_handle_mng.c b/src/cci/cci_handle_mng.c index 73e4cd2..046b741 100644 --- a/src/cci/cci_handle_mng.c +++ b/src/cci/cci_handle_mng.c @@ -186,6 +186,17 @@ hm_put_con_to_pool (int con) return 0; } +int +hm_put_con_to_pool_exceed (void) +{ + if (num_conn_pool >= sizeof (conn_pool) / sizeof (int)) + { + return -1; + } + + return 0; +} + int hm_ip_str_to_addr (char *ip_str, unsigned char *ip_addr) { diff --git a/src/cci/cci_handle_mng.h b/src/cci/cci_handle_mng.h index 00aa323..ebe28ad 100644 --- a/src/cci/cci_handle_mng.h +++ b/src/cci/cci_handle_mng.h @@ -314,6 +314,7 @@ extern int hm_ip_str_to_addr (char *ip_str, unsigned char *ip_addr); extern T_CON_HANDLE *hm_get_con_from_pool (unsigned char *ip_addr, int port, char *dbname, char *dbuser, char *dbpasswd); extern int hm_put_con_to_pool (int con); +extern int hm_put_con_to_pool_exceed (void); extern T_BROKER_VERSION hm_get_broker_version (T_CON_HANDLE * con_handle); extern bool hm_broker_understand_renewed_error_code (T_CON_HANDLE * con_handle); From 64a05eaf3e41147cd3dc69e55657915de0d767a8 Mon Sep 17 00:00:00 2001 From: eido5 Date: Mon, 5 Dec 2022 20:16:41 +0900 Subject: [PATCH 4/7] Edit the function flow and fix the core dump --- src/cci/cas_cci.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/cci/cas_cci.c b/src/cci/cas_cci.c index 5dc67e6..81b4dd9 100644 --- a/src/cci/cas_cci.c +++ b/src/cci/cas_cci.c @@ -712,40 +712,34 @@ cci_disconnect (int mapped_conn_id, T_CCI_ERROR * err_buf) get_last_error (con_handle, err_buf); } - else if (con_handle->broker_info[BROKER_INFO_CCI_PCONNECT] && hm_put_con_to_pool_exceed () == 0) + else { - MUTEX_LOCK (con_handle_table_mutex); - if (con_handle->id < 0 || hm_put_con_to_pool (con_handle->id) < 0) + if (con_handle->broker_info[BROKER_INFO_CCI_PCONNECT]) { - qe_con_close (con_handle); + cci_end_tran_internal (con_handle, CCI_TRAN_ROLLBACK); - error = CCI_ER_BIND_INDEX; - API_ELOG (con_handle, error); - reset_error_buffer (&(con_handle->err_buf)); - set_error_buffer (&(con_handle->err_buf), error, NULL); + MUTEX_LOCK (con_handle_table_mutex); + if (con_handle->id >= 0 && hm_put_con_to_pool (con_handle->id) >= 0) + { + API_ELOG (con_handle, 0); + get_last_error (con_handle, err_buf); + con_handle->used = false; + hm_release_connection (mapped_conn_id, &con_handle); + MUTEX_UNLOCK (con_handle_table_mutex); - hm_delete_connection (mapped_conn_id, &con_handle); - } - else - { - API_ELOG (con_handle, 0); - cci_end_tran_internal (con_handle, CCI_TRAN_ROLLBACK); - hm_release_connection (mapped_conn_id, &con_handle); + return error; + } + MUTEX_UNLOCK (con_handle_table_mutex); } - get_last_error (con_handle, err_buf); - con_handle->used = false; - MUTEX_UNLOCK (con_handle_table_mutex); - } - else - { + error = qe_con_close (con_handle); API_ELOG (con_handle, error); set_error_buffer (&(con_handle->err_buf), error, NULL); get_last_error (con_handle, err_buf); - con_handle->used = false; MUTEX_LOCK (con_handle_table_mutex); + con_handle->used = false; hm_delete_connection (mapped_conn_id, &con_handle); MUTEX_UNLOCK (con_handle_table_mutex); } From 41102aad757b14b47eff3338c7256ad2d121e291 Mon Sep 17 00:00:00 2001 From: eido5 Date: Mon, 5 Dec 2022 20:21:53 +0900 Subject: [PATCH 5/7] Rollback the previous commit --- src/cci/cci_handle_mng.c | 11 ----------- src/cci/cci_handle_mng.h | 1 - 2 files changed, 12 deletions(-) diff --git a/src/cci/cci_handle_mng.c b/src/cci/cci_handle_mng.c index 046b741..73e4cd2 100644 --- a/src/cci/cci_handle_mng.c +++ b/src/cci/cci_handle_mng.c @@ -186,17 +186,6 @@ hm_put_con_to_pool (int con) return 0; } -int -hm_put_con_to_pool_exceed (void) -{ - if (num_conn_pool >= sizeof (conn_pool) / sizeof (int)) - { - return -1; - } - - return 0; -} - int hm_ip_str_to_addr (char *ip_str, unsigned char *ip_addr) { diff --git a/src/cci/cci_handle_mng.h b/src/cci/cci_handle_mng.h index ebe28ad..00aa323 100644 --- a/src/cci/cci_handle_mng.h +++ b/src/cci/cci_handle_mng.h @@ -314,7 +314,6 @@ extern int hm_ip_str_to_addr (char *ip_str, unsigned char *ip_addr); extern T_CON_HANDLE *hm_get_con_from_pool (unsigned char *ip_addr, int port, char *dbname, char *dbuser, char *dbpasswd); extern int hm_put_con_to_pool (int con); -extern int hm_put_con_to_pool_exceed (void); extern T_BROKER_VERSION hm_get_broker_version (T_CON_HANDLE * con_handle); extern bool hm_broker_understand_renewed_error_code (T_CON_HANDLE * con_handle); From 8b1df0a4b43e1195bf2334328709b5461c072f05 Mon Sep 17 00:00:00 2001 From: eido5 Date: Tue, 6 Dec 2022 16:23:25 +0900 Subject: [PATCH 6/7] Edit the if statement range to filter the out of range --- src/cci/cas_cci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cci/cas_cci.c b/src/cci/cas_cci.c index 81b4dd9..aceb27a 100644 --- a/src/cci/cas_cci.c +++ b/src/cci/cas_cci.c @@ -132,6 +132,9 @@ int wsa_initialize (); #define CON_HANDLE_ID_FACTOR 1000000 #define CON_ID(a) ((a) / CON_HANDLE_ID_FACTOR) #define REQ_ID(a) ((a) % CON_HANDLE_ID_FACTOR) + +#define MAX_CON_HANDLE 2048 + /************************************************************************ * PRIVATE FUNCTION PROTOTYPES * ************************************************************************/ @@ -719,7 +722,7 @@ cci_disconnect (int mapped_conn_id, T_CCI_ERROR * err_buf) cci_end_tran_internal (con_handle, CCI_TRAN_ROLLBACK); MUTEX_LOCK (con_handle_table_mutex); - if (con_handle->id >= 0 && hm_put_con_to_pool (con_handle->id) >= 0) + if ((con_handle->id >= 1 && con_handle->id <= MAX_CON_HANDLE) && hm_put_con_to_pool (con_handle->id) >= 0) { API_ELOG (con_handle, 0); get_last_error (con_handle, err_buf); From 70748763e9d6f56482b87eb68cb3e866efdb89c0 Mon Sep 17 00:00:00 2001 From: eido5 Date: Tue, 6 Dec 2022 17:30:40 +0900 Subject: [PATCH 7/7] Set MAX_CON_HANDLE as the public macro --- src/cci/cas_cci.c | 2 -- src/cci/cci_handle_mng.c | 2 -- src/cci/cci_handle_mng.h | 3 +++ 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cci/cas_cci.c b/src/cci/cas_cci.c index aceb27a..f045c2a 100644 --- a/src/cci/cas_cci.c +++ b/src/cci/cas_cci.c @@ -133,8 +133,6 @@ int wsa_initialize (); #define CON_ID(a) ((a) / CON_HANDLE_ID_FACTOR) #define REQ_ID(a) ((a) % CON_HANDLE_ID_FACTOR) -#define MAX_CON_HANDLE 2048 - /************************************************************************ * PRIVATE FUNCTION PROTOTYPES * ************************************************************************/ diff --git a/src/cci/cci_handle_mng.c b/src/cci/cci_handle_mng.c index 73e4cd2..dd7830f 100644 --- a/src/cci/cci_handle_mng.c +++ b/src/cci/cci_handle_mng.c @@ -72,8 +72,6 @@ * PRIVATE DEFINITIONS * ************************************************************************/ -#define MAX_CON_HANDLE 2048 - #define REQ_HANDLE_ALLOC_SIZE 256 #define CCI_MAX_CONNECTION_POOL 256 diff --git a/src/cci/cci_handle_mng.h b/src/cci/cci_handle_mng.h index 00aa323..09b8500 100644 --- a/src/cci/cci_handle_mng.h +++ b/src/cci/cci_handle_mng.h @@ -83,6 +83,9 @@ #define REACHABLE true #define UNREACHABLE false + +#define MAX_CON_HANDLE 2048 + /************************************************************************ * PUBLIC TYPE DEFINITIONS * ************************************************************************/