LibTLS: Ignore empty reads from underlying socket while connecting

We should not expect the server to respond immediately after connecting,
this can manifest as random requests failing (e.g. on https://null.com).
This commit is contained in:
Ali Mohammad Pur 2024-04-26 15:43:24 +02:00 committed by Andreas Kling
commit 2f10243fa2
Notes: sideshowbarker 2024-07-17 22:41:14 +09:00
2 changed files with 4 additions and 1 deletions

View file

@ -66,6 +66,7 @@ ErrorOr<NonnullOwnPtr<TLSv12>> TLSv12::connect(ByteString const& host, u16 port,
};
TRY(promise->await());
tls_socket->m_context.should_expect_successful_read = true;
return tls_socket;
}
@ -83,6 +84,7 @@ ErrorOr<NonnullOwnPtr<TLSv12>> TLSv12::connect(ByteString const& host, Core::Soc
promise->reject(AK::Error::from_string_view(enum_to_string(alert)));
};
TRY(promise->await());
tls_socket->m_context.should_expect_successful_read = true;
return tls_socket;
}
@ -174,7 +176,7 @@ ErrorOr<void> TLSv12::read_from_socket()
consume(read_bytes);
} while (!read_bytes.is_empty() && !m_context.critical_error);
if (read_bytes.is_empty()) {
if (m_context.should_expect_successful_read && read_bytes.is_empty()) {
// read_some() returned an empty span, this is either an EOF (from improper closure)
// or some sort of weird even that is showing itself as an EOF.
// To guard against servers closing the connection weirdly or just improperly, make sure