{"record":{"id":"e5497a38e618e5be","repo":"apache/hadoop","slug":"error-creating-connection","errorCode":null,"errorMessage":"Error creating connection, {}:{}","messagePattern":"Error creating connection, (.+?):(.+?)","errorType":"exception","errorClass":"MetricsException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/sink/GraphiteSink.java","lineNumber":162,"sourceCode":"      if (isConnected()) {\n        throw new MetricsException(\"Already connected to Graphite\");\n      }\n      if (tooManyConnectionFailures()) {\n        // return silently (there was ERROR in logs when we reached limit for the first time)\n        return;\n      }\n      try {\n          // Open a connection to Graphite server.\n        socket = new Socket(serverHost, serverPort);\n        writer = new OutputStreamWriter(socket.getOutputStream(),\n                StandardCharsets.UTF_8);\n      } catch (Exception e) {\n        connectionFailures++;\n        if (tooManyConnectionFailures()) {\n          // first time when connection limit reached, report to logs\n          LOG.error(\"Too many connection failures, would not try to connect again.\");\n        }\n        throw new MetricsException(\"Error creating connection, \" +\n            serverHost + \":\" + serverPort, e);\n      }\n    }\n\n    public void write(String msg) throws IOException {\n      if (!isConnected()) {\n        connect();\n      }\n      if (isConnected()) {\n        writer.write(msg);\n      }\n    }\n\n    public void flush() throws IOException {\n      if (isConnected()) {\n        writer.flush();\n      }\n    }","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/sink/GraphiteSink.java#L144-L180","documentation":"Graphite.connect() opens a new Socket(serverHost, serverPort). Any failure — connection refused, unknown host, connect timeout — increments a connection-failure counter and throws MetricsException(\"Error creating connection, host:port\", e) with the endpoint embedded. After 5 consecutive failures (MAX_CONNECTION_FAILURES) connect() returns silently, an ERROR is logged once, and metrics are dropped without further attempts until the connection succeeds again or the process restarts.","triggerScenarios":"Nothing listening on the configured *.sink.graphite.server_host:server_port (connection refused); typo'd host (UnknownHostException); firewall dropping SYNs (connect timeout); Graphite container restarted on a changed IP.","commonSituations":"Wrong port for the carbon/Graphite listener (plaintext carbon is 2003, not the web 80/2004 pickled port); graphite host migration; DNS failure from the Hadoop node.","solutions":["Verify the endpoint from the Hadoop node: nc -vz <server_host> <server_port> (default 2003)","Fix *.sink.graphite.server_host and *.sink.graphite.server_port in hadoop-metrics2.properties","Check DNS resolution and firewall/egress rules for the port","Restart the daemon after fixing — past 5 consecutive failures the sink stops trying silently"],"exampleFix":"# before\n*.sink.graphite.server_host=graphite.example.com\n*.sink.graphite.server_port=80  # web UI port, carbon not listening here\n\n# after\n*.sink.graphite.server_host=graphite.example.com\n*.sink.graphite.server_port=2003","handlingStrategy":"validation","validationCode":"try (Socket s = new Socket()) {\n  s.connect(new InetSocketAddress(serverHost, serverPort), 3000);\n} catch (IOException e) {\n  throw new IllegalStateException(\"Graphite endpoint \" + serverHost + \":\"\n      + serverPort + \" unreachable — fix metrics2 config before deploy\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  graphite.write(lines);\n} catch (MetricsException e) {\n  // e.getMessage() contains 'Error creating connection, host:port' with the refused/timeout cause\n  LOG.error(\"Cannot reach Graphite at {}: {}\", endpoint, e.getCause(), e);\n}","preventionTips":["Validate the Graphite endpoint from every node class with nc -vz <host> 2003 before shipping the config","Prefer stable DNS names for the graphite host so container/IP changes do not break the sink","Restart daemons after endpoint fixes — past 5 consecutive failures connect() returns silently and metrics are lost"],"tags":["graphite","metrics2","connection-refused","network","configuration"],"backgroundTag":"connection-refused","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}