{"record":{"id":"46dfc888fd0199d2","repo":"alibaba/canal","slug":"requestpost-remote-error-request","errorCode":null,"errorMessage":"requestPost remote error, request : {}","messagePattern":"requestPost remote error, request : (.+?)","errorType":"http","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"instance/manager/src/main/java/com/alibaba/otter/canal/instance/manager/plain/HttpHelper.java","lineNumber":151,"sourceCode":"            if (heads != null) {\n                for (Map.Entry<String, String> entry : heads.entrySet()) {\n                    httpPost.setHeader(entry.getKey(), entry.getValue());\n                }\n            }\n\n            HttpClientContext context = HttpClientContext.create();\n            context.setRequestConfig(config);\n\n            response = httpclient.execute(httpPost, context);\n            int statusCode = response.getStatusLine().getStatusCode();\n            if (statusCode == HttpStatus.SC_OK) {\n                return EntityUtils.toString(response.getEntity());\n            } else {\n                throw new RuntimeException(\"requestPost remote error, request : \" + url + \", statusCode=\" + statusCode\n                                           + \";\" + EntityUtils.toString(response.getEntity()));\n            }\n        } catch (Throwable t) {\n            throw new RuntimeException(\"requestPost remote error, request : \" + url, t);\n        } finally {\n            if (response != null) {\n                try {\n                    response.close();\n                } catch (IOException e) {\n                    // ignore\n                }\n            }\n            if (httpPost != null) {\n                httpPost.releaseConnection();\n            }\n        }\n    }\n\n    public void close() {\n        if (httpclient != null) {\n            try {\n                httpclient.close();","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/instance/manager/src/main/java/com/alibaba/otter/canal/instance/manager/plain/HttpHelper.java#L133-L169","documentation":"Outer catch in HttpHelper.post0() (HttpHelper.java:150-151): catches any Throwable from the POST flow and rethrows it as a new RuntimeException 'requestPost remote error, request : <url>' with the original as the cause. This is the exception callers see. It covers the inner non-200 throw (error 358, preserved as cause), connect/socket timeouts (all three RequestConfig timeouts set to `timeout`), unknown host/connection refused, URIBuilder failures, JSON serialization errors from post() (JSON.toJSONString on the requestBody), and NullPointerException when httpclient is null because the constructor's SSLContext builder failed silently.","triggerScenarios":"Any failure during HttpHelper.post()/post0() — non-200 manager response, network/DNS failure, timeout, malformed URL/URI, requestBody not serializable to JSON, or httpclient null due to constructor SSL init failure. All are uniformly wrapped by the outer catch.","commonSituations":"canal-manager unreachable or down; POST timeout configured too low for manager response; requestBody contains a non-serializable field (fastjson2 throws inside the try); httpclient left null because SSLContextBuilder threw in the constructor (then httpclient.execute NPEs); firewall dropping the manager connection; manager overloaded returning slowly.","solutions":["Classify via getCause(): the inner 'requestPost remote error, request : ..., statusCode=...' → handle per error 358; SocketTimeoutException → raise timeout or reduce manager load; ConnectException/UnknownHostException → network/DNS; NullPointerException → httpclient not built (constructor SSL init failed), restart and verify crypto deps; JSONException → fix the requestBody shape.","Confirm manager reachability: curl -X POST -v <manager-url> from the canal host.","Increase the timeout passed to post() if manager responses are slow.","Validate that the payload passed to post() is POJO-serializable by fastjson2 (avoid cycles, opaque types).","Monitor this RuntimeException as the signal for manager connectivity/health problems."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight: confirm manager reachable and payload serializable\ntry {\n    JSON.toJSONString(requestBody); // throws inside HttpHelper if this fails\n} catch (Exception e) {\n    throw new IllegalArgumentException(\"payload not serializable\", e);\n}\ntry (java.net.Socket s = new java.net.Socket()) {\n    s.connect(managerInetSocketAddress, 3000);\n} catch (IOException e) {\n    throw new IllegalStateException(\"manager unreachable\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    String body = helper.post(url, heads, payload, timeout);\n} catch (RuntimeException e) {\n    Throwable c = e.getCause();\n    if (c instanceof java.net.SocketTimeoutException) {\n        log.warn(\"manager POST timeout to {} (timeout={}ms)\", url, timeout);\n    } else if (c != null && c.getMessage() != null && c.getMessage().contains(\"statusCode=\")) {\n        log.error(\"manager POST non-200: {}\", c.getMessage()); // see error 358\n    } else if (c instanceof NullPointerException) {\n        log.error(\"httpclient null — HttpHelper constructor SSL init failed; restart and verify crypto deps\");\n    } else {\n        log.error(\"manager POST failed to {}\", url, e);\n    }\n    throw e;\n}","preventionTips":["Pre-serialize the payload with fastjson2 to avoid in-try JSON failures.","Ensure JVM crypto libs are present so HttpHelper's httpclient is built (constructor SSL init failure leaves it null → NPE on every call).","Size the `timeout` above manager latency and monitor this RuntimeException.","Validate manager URL/credentials and keep tokens fresh."],"tags":["http","manager-client","rest","post","runtime-exception","network","timeout","error-wrapping"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}