apache/hadoop · error · BadFencingConfigurationException
Unable to parse user and SSH port: {}
Error message
Unable to parse user and SSH port: {} What it means
SshFenceByTcpPort.Args throws BadFencingConfigurationException('Unable to parse user and SSH port: <arg>') when the sshfence argument does not match USER_PORT_RE — pattern '([^:]+?)?(?:\:(\d+))?' i.e. an optional colon-free username and an optional colon-prefixed numeric port.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/SshFenceByTcpPort.java:246
static class Args {
private static final Pattern USER_PORT_RE = Pattern.compile(
"([^:]+?)?(?:\\:(\\d+))?");
private static final int DEFAULT_SSH_PORT = 22;
String user;
int sshPort;
public Args(String arg)
throws BadFencingConfigurationException {
user = System.getProperty("user.name");
sshPort = DEFAULT_SSH_PORT;
// Parse optional user and ssh port
if (arg != null && !arg.isEmpty()) {
Matcher m = USER_PORT_RE.matcher(arg);
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");View on GitHub (pinned to 2add963021)
Solutions
- Use the exact form 'sshfence(<user>:<port>)' with a plain username and a decimal port, e.g. 'sshfence(hdfs:22)'.
- Omit parts entirely ('sshfence(hdfs)' or 'sshfence(:2222)') rather than adding placeholders — user.name and port 22 are the defaults.
- Remove all spaces and extra colons from the argument.
Example fix
<!-- before: hostname wrongly placed in the arg, extra colon --> <value>sshfence(root@nn1:22)</value> <!-- after: username:port only; host is derived from the service address --> <value>sshfence(root:22)</value>
Defensive patterns
Strategy: validation
Validate before calling
// Same rule as USER_PORT_RE: optional colon-free user, optional ':<digits>'
if (arg != null && !arg.isEmpty() && !arg.matches("([^:]+?)?(?::(\\d+))?")) {
throw new IllegalArgumentException("Bad sshfence arg: " + arg);
} Try / catch
try {
new NodeFencer(conf, "sshfence(" + arg + ")");
} catch (BadFencingConfigurationException e) {
// 'Unable to parse user and SSH port' -> fix arg to user:port form
} Prevention
- Remember the sshfence arg is user:port only — never a hostname; the host is taken from the target service address.
- Use the canonical 'sshfence(hdfs:22)' form or omit parts entirely.
- Config-lint any line matching /sshfence\(.*[:,\s@].*\)/ in deploy checks.
When it happens
Trigger: An sshfence(...) entry whose argument has a non-numeric port, spaces, or multiple colons: 'sshfence(hdfs:twentyTwo)', 'sshfence(hdfs :22)', 'sshfence(root:22:33)'. Valid forms are 'sshfence()', 'sshfence(hdfs)', 'sshfence(:2022)', 'sshfence(hdfs:22)'.
Common situations: Putting a hostname in the argument (the target host comes from the service address, not this arg); user names containing ':' or '@'; placeholder text left in templated config; port written with whitespace or units.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unable to parse line: '{}'
- Port number '{}' invalid
- Unable to fence {}. Fencing failed.
- Could not find configured fencing method {}
- Class {} does not implement FenceMethod
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/e86de6400f5c6571.
Report an issue: GitHub.