{"id":"c5ecd945795e580a","repo":"curl/curl","slug":"curl-easy-perform-failed-s-c5ecd9","errorCode":null,"errorMessage":"curl_easy_perform() failed: %s\n","messagePattern":"curl_easy_perform\\(\\) failed: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"docs/examples/imap-noop.c","lineNumber":63,"sourceCode":"\n  curl = curl_easy_init();\n  if(curl) {\n    /* Set username and password */\n    curl_easy_setopt(curl, CURLOPT_USERNAME, \"user\");\n    curl_easy_setopt(curl, CURLOPT_PASSWORD, \"secret\");\n\n    /* This is the server URL */\n    curl_easy_setopt(curl, CURLOPT_URL, \"imap://imap.example.com\");\n\n    /* Set the NOOP command */\n    curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, \"NOOP\");\n\n    /* Perform the custom request */\n    result = curl_easy_perform(curl);\n\n    /* Check for errors */\n    if(result != CURLE_OK)\n      fprintf(stderr, \"curl_easy_perform() failed: %s\\n\",\n              curl_easy_strerror(result));\n\n    /* Always cleanup */\n    curl_easy_cleanup(curl);\n  }\n\n  curl_global_cleanup();\n\n  return (int)result;\n}\n","sourceCodeStart":45,"sourceCodeEnd":74,"githubUrl":"https://github.com/curl/curl/blob/527573490eb2564b3d7c9dd51d8bff963b5d6303/docs/examples/imap-noop.c#L45-L74","documentation":"This error is reported in the IMAP NOOP example when curl_easy_perform() fails after sending the custom command 'NOOP'. NOOP is intentionally a no-op used to keep the session alive and collect server status updates; because it does nothing, a failure almost always indicates a session-level problem (connection, TLS, or authentication) rather than anything intrinsic to NOOP itself.","triggerScenarios":"curl_easy_perform() fails with CURLOPT_URL \"imap://imap.example.com\" and CURLOPT_CUSTOMREQUEST \"NOOP\". Typical causes: wrong credentials (CURLE_LOGIN_DENIED), connection refused/timeout (CURLE_COULDNT_CONNECT / CURLE_OPERATION_TIMEDOUT), server closed the idle connection before NOOP was sent (CURLE_RECV_ERROR), or the server requires TLS so plaintext imap:// is rejected.","commonSituations":"Developers use NOOP as a keep-alive but the server enforces a short idle timeout and closes the socket; the placeholder host imap.example.com does not resolve; placeholder credentials 'user'/'secret' are left in place; corporate IMAP requires imaps:// on 993; the example is run in an environment that blocks outbound port 143.","solutions":["Replace placeholder host and credentials with real values.","Switch to imaps:// with CURLOPT_USE_SSL=CURLUSESSL_ALL for TLS-only servers.","For keep-alive use, send NOOP more frequently than the server's idle timeout, or use the IMAP IDLE extension instead.","Confirm network reachability to port 143/993 and that 'curl -V' includes imap/imaps.","Handle CURLE_RECV_ERROR / CURLE_OPERATION_TIMEDOUT by re-establishing the session."],"exampleFix":"// before\ncurl_easy_setopt(curl, CURLOPT_URL, \"imap://imap.example.com\");\ncurl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, \"NOOP\");\nresult = curl_easy_perform(curl);\nif(result != CURLE_OK)\n  fprintf(stderr, \"curl_easy_perform() failed: %s\\n\", curl_easy_strerror(result));\n\n// after\ncurl_easy_setopt(curl, CURLOPT_URL, \"imaps://imap.example.com\");\ncurl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);\ncurl_easy_setopt(curl, CURLOPT_USERNAME, REAL_USER);\ncurl_easy_setopt(curl, CURLOPT_PASSWORD, REAL_PASS);\ncurl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, \"NOOP\");\nresult = curl_easy_perform(curl);\nif(result != CURLE_OK)\n  fprintf(stderr, \"curl_easy_perform() failed: %s\\n\", curl_easy_strerror(result));","handlingStrategy":"try-catch","validationCode":"/* imap-noop.c: NOOP is cheap but still needs a reachable host + valid cmd */\n#include <string.h>\nCURLcode validate_noop_request(const char *url, const char *custom) {\n  if(!url || strncmp(url, \"imap\", 4) != 0)\n    return CURLE_URL_MALFORMAT;\n  const char *host = url + 4;\n  if(strncmp(host, \"://\", 3) == 0) host += 3; else return CURLE_URL_MALFORMAT;\n  if(*host == '\\0' || *host == '/')\n    return CURLE_URL_MALFORMAT;\n  if(!custom || strcmp(custom, \"NOOP\") != 0)\n    return CURLE_BAD_FUNCTION_ARGUMENT;\n  return CURLE_OK;\n}","typeGuard":"/* NOOP failure is essentially a connection liveness signal */\n#include <curl/curl.h>\nstatic int noop_connection_lost(CURLcode rc) {\n  return rc == CURLE_COULDNT_CONNECT\n      || rc == CURLE_OPERATION_TIMEDOUT\n      || rc == CURLE_RECV_ERROR\n      || rc == CURLE_PARTIAL_FILE;\n}","tryCatchPattern":"/* NOOP: use the result as a keep-alive probe; reconnect on connection loss */\nresult = curl_easy_perform(curl);\nif(result != CURLE_OK) {\n  if(noop_connection_lost(result)) {\n    fprintf(stderr, \"Connection lost during NOOP; tearing down\\n\");\n    curl_easy_cleanup(curl);\n    curl = rebuild_session();            /* reconnect + re-authenticate */\n  } else {\n    fprintf(stderr, \"curl_easy_perform() failed: %s\\n\", curl_easy_strerror(result));\n  }\n}\ncurl_easy_cleanup(curl);","preventionTips":["Use NOOP as a liveness check between long-idle operations to keep the session alive.","Set CURLOPT_CONNECTTIMEOUT so a dead server fails NOOP quickly rather than blocking.","Treat a NOOP failure as a signal to reconnect and re-authenticate, not just log.","Don't expect NOOP to return data; any untagged response is bonus status, not the goal."],"tags":["libcurl","imap","custom-request","keep-alive","network","authentication"],"analyzedSha":"527573490eb2564b3d7c9dd51d8bff963b5d6303","analyzedAt":"2026-08-01T21:00:26.351Z","schemaVersion":2}