Skip to content

Commit b5cdb8a

Browse files
debug
1 parent 10f4db4 commit b5cdb8a

File tree

3 files changed

+59
-40
lines changed

3 files changed

+59
-40
lines changed

lib/http_perform.c

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,26 @@ int my_trace(CURL *handle, curl_infotype type,
110110
text = "=> Send header";
111111
break;
112112
case CURLINFO_DATA_OUT:
113+
// temporarily disable output for debugging
114+
return 0;
113115
text = "=> Send data";
114116
break;
115117
case CURLINFO_SSL_DATA_OUT:
118+
// temporarily disable output for debugging
119+
return 0;
116120
text = "=> Send SSL data";
117121
break;
118122
case CURLINFO_HEADER_IN:
119123
text = "<= Recv header";
120124
break;
121125
case CURLINFO_DATA_IN:
126+
// temporarily disable output for debugging
127+
return 0;
122128
text = "<= Recv data";
123129
break;
124130
case CURLINFO_SSL_DATA_IN:
131+
// temporarily disable output for debugging
132+
return 0;
125133
text = "<= Recv SSL data";
126134
break;
127135
}
@@ -512,28 +520,49 @@ sf_bool STDCALL http_perform(CURL *curl,
512520
if (curl_error_buffer[0] != '\0') {
513521
log_error("curl error buffer: %s", curl_error_buffer);
514522
}
515-
if (res == CURLE_COULDNT_CONNECT && curl_retry_ctx.retry_count <
516-
(unsigned)retry_on_curle_couldnt_connect_count)
517-
{
518-
retry = SF_BOOLEAN_TRUE;
519-
uint32 next_sleep_in_secs = retry_ctx_next_sleep(&curl_retry_ctx);
520-
log_error(
521-
"curl_easy_perform() failed connecting to server on attempt %d, "
522-
"will retry after %d second",
523-
curl_retry_ctx.retry_count,
524-
next_sleep_in_secs);
525-
sf_sleep_ms(next_sleep_in_secs*1000);
526-
} else if ((res == CURLE_OPERATION_TIMEDOUT) ||
527-
(res == CURLE_PARTIAL_FILE)) {
528-
// retry directly without backoff when timeout is triggered by renew
529-
if ((res == CURLE_OPERATION_TIMEDOUT) &&
530-
(renew_timeout > 0) && (curl_timeout == renew_timeout))
531-
{
532-
retry = SF_BOOLEAN_TRUE;
533-
}
534-
// otherwise retry with backoff
535-
else if (((uint64)(time(NULL) - elapsedRetryTime) < curl_retry_ctx.retry_timeout) &&
536-
((retry_max_count <= 0) || (curl_retry_ctx.retry_count < (unsigned)retry_max_count)))
523+
if (res == CURLE_COULDNT_CONNECT &&
524+
curl_retry_ctx.retry_count < (unsigned)retry_on_curle_couldnt_connect_count)
525+
{
526+
retry = SF_BOOLEAN_TRUE;
527+
uint32 next_sleep_in_secs = retry_ctx_next_sleep(&curl_retry_ctx);
528+
log_error(
529+
"curl_easy_perform() failed connecting to server on attempt %d, "
530+
"will retry after %d second",
531+
curl_retry_ctx.retry_count,
532+
next_sleep_in_secs);
533+
sf_sleep_ms(next_sleep_in_secs*1000);
534+
} else if ((res == CURLE_OPERATION_TIMEDOUT) &&
535+
((renew_timeout > 0) && (curl_timeout == renew_timeout)))
536+
// retry directly without backoff when timeout is triggered by renew
537+
{
538+
retry = SF_BOOLEAN_TRUE;
539+
}
540+
// retry with backoff on any other curl error except particular non-retryable ones
541+
else {
542+
char msg[1024];
543+
if (res == CURLE_SSL_CACERT_BADFILE) {
544+
sf_sprintf(msg, sizeof(msg), "curl_easy_perform() failed. err: %s, CA Cert file: %s",
545+
curl_easy_strerror(res), CA_BUNDLE_FILE ? CA_BUNDLE_FILE : "Not Specified");
546+
msg[sizeof(msg) - 1] = (char)0;
547+
log_error(msg);
548+
SET_SNOWFLAKE_ERROR(error, SF_STATUS_ERROR_CURL,
549+
msg,
550+
SF_SQLSTATE_UNABLE_TO_CONNECT);
551+
}
552+
else if (res == CURLE_SSL_INVALIDCERTSTATUS) {
553+
log_error("Detected CURLE_SSL_INVALIDCERTSTATUS (91) - likely OCSP/CRL validation failure.");
554+
SET_SNOWFLAKE_ERROR(error, SF_STATUS_ERROR_CURL,
555+
msg,
556+
SF_SQLSTATE_UNABLE_TO_CONNECT);
557+
}
558+
// otherwise retry with backoff
559+
else {
560+
sf_sprintf(msg, sizeof(msg), "curl_easy_perform() failed: %s", curl_easy_strerror(res));
561+
msg[sizeof(msg) - 1] = (char)0;
562+
log_warn(msg);
563+
564+
if (((uint64)(time(NULL) - elapsedRetryTime) < curl_retry_ctx.retry_timeout) &&
565+
((retry_max_count <= 0) || (curl_retry_ctx.retry_count < (unsigned)retry_max_count)))
537566
{
538567
uint32 next_sleep_in_secs = retry_ctx_next_sleep(&curl_retry_ctx);
539568
log_debug(
@@ -553,24 +582,7 @@ sf_bool STDCALL http_perform(CURL *curl,
553582
SF_SQLSTATE_UNABLE_TO_CONNECT);
554583
}
555584
}
556-
else {
557-
char msg[1024];
558-
if (res == CURLE_SSL_CACERT_BADFILE) {
559-
sf_sprintf(msg, sizeof(msg), "curl_easy_perform() failed. err: %s, CA Cert file: %s",
560-
curl_easy_strerror(res), CA_BUNDLE_FILE ? CA_BUNDLE_FILE : "Not Specified");
561-
}
562-
else {
563-
sf_sprintf(msg, sizeof(msg), "curl_easy_perform() failed: %s", curl_easy_strerror(res));
564-
}
565-
msg[sizeof(msg)-1] = (char)0;
566-
log_error(msg);
567-
if (res == CURLE_SSL_INVALIDCERTSTATUS) {
568-
log_error("Detected CURLE_SSL_INVALIDCERTSTATUS (91) - likely OCSP/CRL validation failure.");
569-
}
570-
SET_SNOWFLAKE_ERROR(error, SF_STATUS_ERROR_CURL,
571-
msg,
572-
SF_SQLSTATE_UNABLE_TO_CONNECT);
573-
}
585+
}
574586
} else {
575587
if (curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code) !=
576588
CURLE_OK) {

tests/test_lob.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ void verify_result(SF_STMT *sfstmt, int exp_size, sf_bool accurate_desc, sf_bool
9898
void test_lob_setup(SF_CONNECT **out_sf, SF_STMT **out_sfstmt, sf_bool use_arrow)
9999
{
100100
SF_CONNECT *sf = setup_snowflake_connection();
101+
// temporarily enable for debugging
102+
snowflake_global_set_attribute(SF_GLOBAL_DEBUG, &SF_BOOLEAN_TRUE);
101103
/* extend timeout to retrive large query response with LOB data */
102104
int64 timeout = 1200;
103105
snowflake_set_attribute(sf, SF_CON_NETWORK_TIMEOUT, &timeout);

tests/test_simple_put.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,9 +1623,14 @@ void test_2GBlarge_get(void **unused)
16231623
}
16241624
#endif
16251625

1626+
// temporarily enable for debugging
1627+
snowflake_global_set_attribute(SF_GLOBAL_DEBUG, &SF_BOOLEAN_TRUE);
1628+
16261629
std::string getcmd = std::string("get @%test_small_put/") + FILE_NAME_2GB +
16271630
" file://" + TestSetup::getDataDir();
16281631
test_simple_get_data(getcmd.c_str(), std::to_string(FILE_SIZE_2GB).c_str());
1632+
1633+
snowflake_global_set_attribute(SF_GLOBAL_DEBUG, &SF_BOOLEAN_FALSE);
16291634
}
16301635

16311636
void test_simple_put_with_proxy(void **unused)

0 commit comments

Comments
 (0)