http: notify client when connection failed

Type: fix

Change-Id: I87054e9667fe990d9a2dc3950bc3ce348460018a
Signed-off-by: Matus Fabian <matfabia@cisco.com>
This commit is contained in:
Matus Fabian
2024-05-13 10:29:11 +02:00
committed by Florin Coras
parent b7a9ed75fb
commit 3d00893c37
3 changed files with 29 additions and 5 deletions

View File

@ -12,7 +12,7 @@ import (
func init() {
registerNsTests(HttpTpsTest)
registerVethTests(HttpCliTest)
registerVethTests(HttpCliTest, HttpCliConnectErrorTest)
registerNoTopoTests(NginxHttp3Test, NginxAsServerTest,
NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest, HeaderServerTest,
HttpStaticMovedTest, HttpStaticNotFoundTest, HttpCliMethodNotAllowedTest,
@ -58,6 +58,20 @@ func HttpCliTest(s *VethsSuite) {
s.assertContains(o, "<html>", "<html> not found in the result!")
}
func HttpCliConnectErrorTest(s *VethsSuite) {
clientContainer := s.getContainerByName("client-vpp")
serverVeth := s.getInterfaceByName(serverInterfaceName)
uri := "http://" + serverVeth.ip4AddressString() + "/80"
o := clientContainer.vppInstance.vppctl("http cli client" +
" uri " + uri + " query /show/vlib/graph")
s.log(o)
s.assertContains(o, "failed to connect")
}
func NginxHttp3Test(s *NoTopoSuite) {
s.SkipUnlessExtendedTestsBuilt()

View File

@ -67,6 +67,7 @@ typedef enum
{
HCC_REPLY_RECEIVED = 100,
HCC_TRANSPORT_CLOSED,
HCC_CONNECT_FAILED,
} hcc_cli_signal_t;
static hcc_main_t hcc_main;
@ -135,6 +136,8 @@ hcc_ts_connected_callback (u32 app_index, u32 hc_index, session_t *as,
{
clib_warning ("connected error: hc_index(%d): %U", hc_index,
format_session_error, err);
vlib_process_signal_event_mt (hcm->vlib_main, hcm->cli_node_index,
HCC_CONNECT_FAILED, 0);
return -1;
}
@ -425,6 +428,9 @@ hcc_run (vlib_main_t *vm, int print_output)
case HCC_TRANSPORT_CLOSED:
err = clib_error_return (0, "error, transport closed");
break;
case HCC_CONNECT_FAILED:
err = clib_error_return (0, "failed to connect");
break;
default:
err = clib_error_return (0, "unexpected event %d", event_type);
break;

View File

@ -267,17 +267,21 @@ http_ts_connected_callback (u32 http_app_index, u32 ho_hc_index, session_t *ts,
app_worker_t *app_wrk;
int rv;
ho_hc = http_conn_get_w_thread (ho_hc_index, 0);
ASSERT (ho_hc->state == HTTP_CONN_STATE_CONNECTING);
if (err)
{
clib_warning ("ERROR: %d", err);
clib_warning ("half-open hc index %d, error: %U", ho_hc_index,
format_session_error, err);
app_wrk = app_worker_get_if_valid (ho_hc->h_pa_wrk_index);
if (app_wrk)
app_worker_connect_notify (app_wrk, 0, err, ho_hc->h_pa_app_api_ctx);
return 0;
}
new_hc_index = http_conn_alloc_w_thread (ts->thread_index);
hc = http_conn_get_w_thread (new_hc_index, ts->thread_index);
ho_hc = http_conn_get_w_thread (ho_hc_index, 0);
ASSERT (ho_hc->state == HTTP_CONN_STATE_CONNECTING);
clib_memcpy_fast (hc, ho_hc, sizeof (*hc));