apache/hadoop · error · BadFencingConfigurationException

Port number '{}' invalid

Error message

Port number '{}' invalid

What it means

SshFenceByTcpPort.parseConfiggedPort() wraps NumberFormatException in BadFencingConfigurationException("Port number '<portStr>' invalid") when the port segment of the sshfence argument passed the USER_PORT_RE regex (colon followed to end) but is not parseable by Integer.parseInt.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/SshFenceByTcpPort.java:263

        if (!m.matches()) {
          throw new BadFencingConfigurationException(
              "Unable to parse user and SSH port: "+ arg);
        }
        if (m.group(1) != null) {
          user = m.group(1);
        }
        if (m.group(2) != null) {
          sshPort = parseConfiggedPort(m.group(2));
        }
      }
    }

    private int parseConfiggedPort(String portStr)
        throws BadFencingConfigurationException {
      try {
        return Integer.parseInt(portStr);
      } catch (NumberFormatException nfe) {
        throw new BadFencingConfigurationException(
            "Port number '" + portStr + "' invalid");
      }
    }
  }

  /**
   * Adapter from JSch's logger interface to our log4j
   */
  private static class LogAdapter implements com.jcraft.jsch.Logger {
    static final Logger LOG = LoggerFactory.getLogger(
        SshFenceByTcpPort.class.getName() + ".jsch");

    @Override
    public boolean isEnabled(int level) {
      switch (level) {
      case com.jcraft.jsch.Logger.DEBUG:
        return LOG.isDebugEnabled();
      case com.jcraft.jsch.Logger.INFO:

View on GitHub (pinned to 2add963021)

Solutions

  1. Write a decimal TCP port between 1 and 65535, e.g. 'sshfence(hdfs:22)'.
  2. If hdfs-site.xml is templated, verify the substituted value is numeric.
  3. Check for stray whitespace or units in the port string.

Example fix

<!-- before -->
<value>sshfence(hdfs:SSH_PORT)</value>

<!-- after -->
<value>sshfence(hdfs:22)</value>
Defensive patterns

Strategy: validation

Validate before calling

String port = arg.substring(arg.indexOf(':') + 1);
int p = Integer.parseInt(port); // NumberFormatException if non-numeric
if (p <= 0 || p > 65535) throw new IllegalArgumentException("port out of range");

Try / catch

try {
  new NodeFencer(conf, "sshfence(hdfs:" + portStr + ")");
} catch (BadFencingConfigurationException e) {
  // 'Port number invalid' -> replace with a decimal TCP port
}

Prevention

When it happens

Trigger: An sshfence argument whose port group is non-numeric or empty in a way the regex still accepted group(2), e.g. 'sshfence(hdfs:0x16)', 'sshfence(hdfs:22 )', or oversized/out-of-range values that overflow int parsing.

Common situations: Typo in the port; config templating substituting a variable name instead of a number; copied example with placeholder text in the port position.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/8a4b9eefb532f9f7. Report an issue: GitHub.