From 19b80d6db3d980132846adc61d05d48ca852e3bc Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 19 Jul 2011 00:14:58 +1000 Subject: [PATCH 1/2] Curl's global init can trample dynamically allocated data so do it before anything else. --- main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 8556c158..c1591a8f 100644 --- a/main.c +++ b/main.c @@ -2158,6 +2158,11 @@ int main (int argc, char *argv[]) char name[256]; struct tm tm; + /* This dangerous functions tramples random dynamically allocated + * variables so do it before anything at all */ + if (unlikely(curl_global_init(CURL_GLOBAL_ALL))) + return 1; + if (unlikely(pthread_mutex_init(&hash_lock, NULL))) return 1; if (unlikely(pthread_mutex_init(&qd_lock, NULL))) @@ -2272,8 +2277,6 @@ int main (int argc, char *argv[]) } } - if (unlikely(curl_global_init(CURL_GLOBAL_ALL))) - return 1; #ifdef HAVE_SYSLOG_H if (use_syslog) openlog("cpuminer", LOG_PID, LOG_USER); @@ -2472,7 +2475,6 @@ int main (int argc, char *argv[]) applog(LOG_INFO, "workio thread dead, exiting."); gettimeofday(&total_tv_end, NULL); - curl_global_cleanup(); disable_curses(); if (!opt_quiet && successful_connect) print_summary(); @@ -2482,6 +2484,7 @@ int main (int argc, char *argv[]) if (opt_n_threads) free(cpus); + curl_global_cleanup(); return 0; } From 44c975be65f9ac3d7a83bb661348fbd0021d1d1a Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 19 Jul 2011 01:39:22 +1000 Subject: [PATCH 2/2] Long timeouts are causing reset connections and longpoll can recover if the connection needs to be restarted, so remove the timeout settings. --- util.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/util.c b/util.c index 02a488ea..6357c254 100644 --- a/util.c +++ b/util.c @@ -250,7 +250,6 @@ json_t *json_rpc_call(CURL *curl, const char *url, struct curl_slist *headers = NULL; char len_hdr[64], user_agent_hdr[128]; char curl_err_str[CURL_ERROR_SIZE]; - long timeout = longpoll ? (60 * 60) : (60 * 10); struct header_info hi = { }; bool lp_scanning = false; @@ -272,7 +271,6 @@ json_t *json_rpc_call(CURL *curl, const char *url, curl_easy_setopt(curl, CURLOPT_READDATA, &upload_data); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_err_str); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); - curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); if (lp_scanning) { curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, resp_hdr_cb); curl_easy_setopt(curl, CURLOPT_HEADERDATA, &hi);