From 35d5a0fae00af782663e95f4ebea69299bb7edd6 Mon Sep 17 00:00:00 2001 From: Ganesh Murthy Date: Mon, 15 Jul 2024 16:20:27 -0400 Subject: [PATCH] Fixes #1568: Modified qd_hash_retrieve_str() to return QD_ERROR_NOT_FOUND is not value is found for passed in key. Minor changes to http2_observer as well (#1569) --- src/hash.c | 3 ++- src/observers/http2/http2_observer.c | 9 ++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hash.c b/src/hash.c index cf3a9d9e8..9c52e5391 100644 --- a/src/hash.c +++ b/src/hash.c @@ -410,10 +410,11 @@ qd_error_t qd_hash_retrieve_str(qd_hash_t *h, const unsigned char *key, void **v key); if (item) { *val = item->v.val; + return QD_ERROR_NONE; } else { *val = 0; + return QD_ERROR_NOT_FOUND; } - return QD_ERROR_NONE; } diff --git a/src/observers/http2/http2_observer.c b/src/observers/http2/http2_observer.c index 7b9a0892b..fbb544dc7 100644 --- a/src/observers/http2/http2_observer.c +++ b/src/observers/http2/http2_observer.c @@ -96,7 +96,7 @@ int on_begin_header_callback(qd_http2_decoder_connection_t *conn_state, // HTTP2 can have more than one header frame come in for the same request. // For example, in GRPC, we can get a header at the beginning of the stream // and a footer at the end of the stream and both these frames are HEADER type frames. - if (error == QD_ERROR_NONE && !stream_info) { + if (error == QD_ERROR_NOT_FOUND) { qd_http2_stream_info_t *stream_info = new_qd_http2_stream_info_t(); ZERO(stream_info); DEQ_INSERT_TAIL(transport_handle->http2.streams, stream_info); @@ -118,7 +118,7 @@ int on_begin_header_callback(qd_http2_decoder_connection_t *conn_state, } } else { // from_client - if (error != QD_ERROR_NONE && stream_info) { + if (error != QD_ERROR_NOT_FOUND && stream_info) { vflow_latency_end(stream_info->vflow); } } @@ -149,7 +149,7 @@ static int on_header_recv_callback(qd_http2_decoder_connection_t *conn_state, // // Set the http request method (GET, POST etc) on the stream's vflow object. // - if(error == QD_ERROR_NONE) { + if(error == QD_ERROR_NOT_FOUND) { qd_log(LOG_HTTP2_DECODER, QD_LOG_ERROR, "[C%"PRIu64"] on_header_recv_callback - HTTP_METHOD -could not find in the hashtable, stream_id=%" PRIu32, transport_handle->conn_id, stream_id); } else { @@ -161,9 +161,8 @@ static int on_header_recv_callback(qd_http2_decoder_connection_t *conn_state, assert(stream_info != 0); // // We expect that the above call to get_stream_info_from_hashtable() should return a valid stream_info object. - // The qd_hash_retrieve_str() function always returns QD_ERROR_NONE but it is an error if we did not get back a non-zero stream_info object. // - if(error == QD_ERROR_NONE && stream_info == 0) { + if(error == QD_ERROR_NOT_FOUND) { qd_log(LOG_HTTP2_DECODER, QD_LOG_ERROR, "[C%"PRIu64"] on_header_recv_callback - HTTP_STATUS -could not find in the hashtable, stream_id=%" PRIu32, transport_handle->conn_id, stream_id); } else {