Skip to content

Commit 492ab3b

Browse files
bneradtcmcfarlen
authored andcommitted
Fix errno assertion failure in retry_server_connection_not_open (#12657)
This ensures that cause_of_death_errno is properly set with appropriate error codes (EBADMSG for protocol errors, EPIPE for closed connections) before retry attempts are made via set_connect_fail() when error states are detected. Fixes: #12654 (cherry picked from commit 6195c2b)
1 parent 07e756b commit 492ab3b

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/proxy/http/HttpSM.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,13 @@ HttpSM::state_raw_http_server_open(int event, void *data)
11221122
case VC_EVENT_ERROR:
11231123
case VC_EVENT_EOS:
11241124
case NET_EVENT_OPEN_FAILED:
1125+
if (t_state.cause_of_death_errno == -UNKNOWN_INTERNAL_ERROR) {
1126+
if (event == VC_EVENT_EOS) {
1127+
t_state.set_connect_fail(EPIPE);
1128+
} else {
1129+
t_state.set_connect_fail(EIO);
1130+
}
1131+
}
11251132
t_state.current.state = HttpTransact::OPEN_RAW_ERROR;
11261133
// use this value just to get around other values
11271134
t_state.hdr_info.response_error = HttpTransact::STATUS_CODE_SERVER_ERROR;
@@ -2022,9 +2029,7 @@ HttpSM::state_read_server_response_header(int event, void *data)
20222029
if (allow_error == false) {
20232030
SMDbg(dbg_ctl_http_seq, "Error parsing server response header");
20242031
t_state.current.state = HttpTransact::PARSE_ERROR;
2025-
// We set this to 0 because otherwise HttpTransact::retry_server_connection_not_open
2026-
// will raise an assertion if the value is the default UNKNOWN_INTERNAL_ERROR.
2027-
t_state.cause_of_death_errno = 0;
2032+
t_state.set_connect_fail(EBADMSG);
20282033

20292034
// If the server closed prematurely on us, use the
20302035
// server setup error routine since it will forward
@@ -5155,6 +5160,9 @@ HttpSM::send_origin_throttled_response()
51555160
if (t_state.dns_info.looking_up != ResolveInfo::PARENT_PROXY) {
51565161
t_state.current.retry_attempts.maximize(t_state.configured_connect_attempts_max_retries());
51575162
}
5163+
if (t_state.cause_of_death_errno == -UNKNOWN_INTERNAL_ERROR) {
5164+
t_state.set_connect_fail(EUSERS); // Too many users.
5165+
}
51585166
t_state.current.state = HttpTransact::OUTBOUND_CONGESTION;
51595167
call_transact_and_set_next_state(HttpTransact::HandleResponse);
51605168
}
@@ -5568,6 +5576,9 @@ HttpSM::do_http_server_open(bool raw, bool only_direct)
55685576
httpSessionManager.purge_keepalives();
55695577
// Eventually may want to have a queue as the origin_max_connection does to allow for a combination
55705578
// of retries and errors. But at this point, we are just going to allow the error case.
5579+
if (t_state.cause_of_death_errno == -UNKNOWN_INTERNAL_ERROR) {
5580+
t_state.set_connect_fail(ENFILE); // Too many open files in system.
5581+
}
55715582
t_state.current.state = HttpTransact::CONNECTION_ERROR;
55725583
call_transact_and_set_next_state(HttpTransact::HandleResponse);
55735584
return;

src/proxy/http/HttpTransact.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3749,6 +3749,20 @@ HttpTransact::handle_response_from_server(State *s)
37493749
case CONNECTION_CLOSED:
37503750
case BAD_INCOMING_RESPONSE:
37513751

3752+
// Ensure cause_of_death_errno is set for all error states if not already set.
3753+
// This prevents the assertion failure in retry_server_connection_not_open.
3754+
if (s->cause_of_death_errno == -UNKNOWN_INTERNAL_ERROR) {
3755+
if (s->current.state == PARSE_ERROR || s->current.state == BAD_INCOMING_RESPONSE) {
3756+
s->set_connect_fail(EBADMSG);
3757+
} else if (s->current.state == CONNECTION_CLOSED) {
3758+
s->set_connect_fail(EPIPE);
3759+
} else {
3760+
// Generic fallback for OPEN_RAW_ERROR, CONNECTION_ERROR,
3761+
// STATE_UNDEFINED, and any other unexpected error states.
3762+
s->set_connect_fail(EIO);
3763+
}
3764+
}
3765+
37523766
if (is_server_negative_cached(s)) {
37533767
max_connect_retries = s->txn_conf->connect_attempts_max_retries_down_server - 1;
37543768
} else {

0 commit comments

Comments
 (0)