cloudfuse icon indicating copy to clipboard operation
cloudfuse copied to clipboard

Curl timeout is too short for some connections

Open RandyLevensalor opened this issue 12 years ago • 1 comments

When running cloudefuse I would receive a "Unable to authenticate." error. Using the same authentication url and credentials, I was able to authenticate.

The root cause is that my connection was timing out. Please increase the default or add an option to set the timeout.

I will post a patch that adds a connect_timeout option.

RandyLevensalor avatar Mar 03 '12 18:03 RandyLevensalor

From 7e9c0e32912ececc3a9cde5f0f11465f2ec9a2dd Mon Sep 17 00:00:00 2001 From: Randy Levensalor [email protected] Date: Sat, 3 Mar 2012 11:17:02 -0700 Subject: [PATCH] Committer: Randy Levensalor [email protected]

On branch add_connect_timeout Changes to be committed: modified: cloudfsapi.c modified: cloudfsapi.h

modified: cloudfuse.c

cloudfsapi.c | 12 +++++++++--- cloudfsapi.h | 1 + cloudfuse.c | 10 ++++++++-- 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/cloudfsapi.c b/cloudfsapi.c index ba14035..bd136b4 100644 --- a/cloudfsapi.c +++ b/cloudfsapi.c @@ -24,6 +24,7 @@ static pthread_mutex_t pool_mut; static CURL *curl_pool[1024]; static int curl_pool_count = 0; static int debug = 0; +static int connect_timeout = 10;

#ifdef HAVE_OPENSSL #include <openssl/crypto.h> @@ -104,7 +105,7 @@ static CURL *get_connection(const char *path) curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);

  • curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
  • curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, connect_timeout); return curl; }

@@ -354,6 +355,11 @@ int create_directory(const char *path) return (response >= 200 && response < 300); }

+void cloudfs_connect_timeout(int conn_timeout) +{

  • connect_timeout = conn_timeout; +}

void cloudfs_debug(int dbg) { debug = dbg; @@ -411,8 +417,8 @@ int cloudfs_connect(char *username, char *password, char *authurl, int use_snet) curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);

  • curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10);
  • curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10);
  • curl_easy_setopt(curl, CURLOPT_TIMEOUT, connect_timeout);
  • curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, connect_timeout); curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response); curl_slist_free_all(headers); diff --git a/cloudfsapi.h b/cloudfsapi.h index 54a5871..0ee3e77 100644 --- a/cloudfsapi.h +++ b/cloudfsapi.h @@ -31,6 +31,7 @@ int copy_object(const char *src, const char *dst); int create_directory(const char *label); int cloudfs_connect(char *username, char *password, char *authurl, int snet_rewrite); void cloudfs_debug(int dbg); +void cloudfs_connect_timeout(int conn_timeout); void free_dir_list(dir_entry *dir_list); int object_truncate(const char *path, off_t size);

diff --git a/cloudfuse.c b/cloudfuse.c index bf7e195..84854c5 100644 --- a/cloudfuse.c +++ b/cloudfuse.c @@ -21,6 +21,7 @@ #define OPTION_SIZE 1024

static int cache_timeout; +static int connect_timeout;

typedef struct dir_cache { @@ -423,12 +424,14 @@ static struct options { char cache_timeout[OPTION_SIZE]; char authurl[OPTION_SIZE]; char use_snet[OPTION_SIZE];

  • char connect_timeout[OPTION_SIZE]; } options = { .username = "", .api_key = "", .cache_timeout = "600", .authurl = "https://auth.api.rackspacecloud.com/v1.0", .use_snet = "false",
  • .connect_timeout = "10", };

int parse_option(void *data, const char *arg, int key, struct fuse_args *outargs) @@ -437,7 +440,8 @@ int parse_option(void *data, const char *arg, int key, struct fuse_args *outargs sscanf(arg, " api_key = %[^\r\n ]", options.api_key) || sscanf(arg, " cache_timeout = %[^\r\n ]", options.cache_timeout) || sscanf(arg, " authurl = %[^\r\n ]", options.authurl) ||

  •  sscanf(arg, " use_snet = %[^\r\n ]", options.use_snet))
    
  •  sscanf(arg, " use_snet = %[^\r\n ]", options.use_snet) ||
    
  •  sscanf(arg, " connect_timeout = %[^\r\n ]", options.connect_timeout))
    

    return 0; if (!strcmp(arg, "-f") || !strcmp(arg, "-d") || !strcmp(arg, "debug")) cloudfs_debug(1); @@ -462,7 +466,8 @@ int main(int argc, char **argv) }

    cache_timeout = atoi(options.cache_timeout);

  • connect_timeout = atoi(options.connect_timeout);

  • cloudfs_connect_timeout(connect_timeout); if (!_options.username || !_options.api_key) { fprintf(stderr, "Unable to determine username and API key.\n\n"); @@ -474,6 +479,7 @@ int main(int argc, char **argv) fprintf(stderr, " cache_timeout=[seconds for directory caching]\n"); fprintf(stderr, " use_snet=[True to connect to snet]\n"); fprintf(stderr, " authurl=[used for testing]\n");

  • fprintf(stderr, " connection_timeout=[seconds for curl timeout]\n"); return 1; }

1.7.5.4

RandyLevensalor avatar Mar 03 '12 18:03 RandyLevensalor