@@ -88,19 +88,32 @@ public class Starfish.Core.Client : Object {
88
88
int redirect_count = 0 ,
89
89
bool follow_redirects = true ,
90
90
bool accept_mismatched_cert = false ,
91
- bool should_use_cleint_cert = false
91
+ bool should_use_cleint_cert = false ,
92
+ int tls_retry_count = 0
92
93
) {
93
94
SocketConnection conn;
94
95
CertError ? cert_error = null ;
95
96
CertInfo ? cert_info = null ;
96
97
CertInfo ? client_cert_info = null ;
98
+ bool is_retryable_tls_issue = false ;
97
99
try {
98
100
var socket_client = new SocketClient () {
99
101
tls = true ,
100
102
tls_validation_flags = TlsCertificateFlags . VALIDATE_ALL ,
101
103
timeout = 100000000
102
104
};
105
+ SocketClientEvent ? previous_event = null ;
103
106
socket_client. event. connect ((event, connectable, conn) = > {
107
+ if (previous_event == SocketClientEvent . TLS_HANDSHAKING
108
+ && event == SocketClientEvent . RESOLVING
109
+ && tls_retry_count < 3
110
+ ) {
111
+ warning (" Detected issue in TLS handshake, will attempt to retry it." );
112
+ is_retryable_tls_issue = true ;
113
+ } else {
114
+ previous_event = event;
115
+ }
116
+
104
117
if (event == SocketClientEvent . TLS_HANDSHAKING ) {
105
118
var tls_conn = (TlsClientConnection ) conn;
106
119
if (should_use_cleint_cert) {
@@ -139,6 +152,9 @@ public class Starfish.Core.Client : Object {
139
152
var request = (uri. to_string () + " \r\n " ). data;
140
153
yield conn. output_stream. write_async (request, Priority . DEFAULT , cancel);
141
154
} catch (Error err) {
155
+ if (is_retryable_tls_issue) {
156
+ return yield load_gemini (uri, cancel, redirect_count, follow_redirects, accept_mismatched_cert, should_use_cleint_cert, tls_retry_count + 1 );
157
+ }
142
158
if (cert_error != null ) {
143
159
if (cert_error is CertError . PARSING_ERROR || cert_error is CertError . FINGERPRINTING_ERROR ) {
144
160
return new InternalErrorResponse .server_certificate_invalid (cert_info, uri, cert_error. message);
0 commit comments