diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ShellBasedUnixGroupsMapping.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ShellBasedUnixGroupsMapping.java index 4146e7bc9b..94698d8446 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ShellBasedUnixGroupsMapping.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/ShellBasedUnixGroupsMapping.java @@ -157,6 +157,32 @@ protected String[] getGroupsIDForUserCommand(String userName) { return Shell.getGroupsIDForUserCommand(userName); } + /** + * Check if the executor had a timeout and logs the event. + * @param executor to check + * @param user user to log + * @return true if timeout has occurred + */ + private boolean handleExecutorTimeout( + ShellCommandExecutor executor, + String user) { + // If its a shell executor timeout, indicate so in the message + // but treat the result as empty instead of throwing it up, + // similar to how partial resolution failures are handled above + if (executor.isTimedOut()) { + LOG.warn( + "Unable to return groups for user '{}' as shell group lookup " + + "command '{}' ran longer than the configured timeout limit of " + + "{} seconds.", + user, + Joiner.on(' ').join(executor.getExecString()), + timeout + ); + return true; + } + return false; + } + /** * Get the current user's group list from Unix by running the command 'groups' * NOTE. For non-existing user it will return EMPTY list. @@ -174,26 +200,19 @@ private List getUnixGroups(String user) throws IOException { executor.execute(); groups = resolveFullGroupNames(executor.getOutput()); } catch (ExitCodeException e) { - try { - groups = resolvePartialGroupNames(user, e.getMessage(), - executor.getOutput()); - } catch (PartialGroupNameException pge) { - LOG.warn("unable to return groups for user {}", user, pge); + if (handleExecutorTimeout(executor, user)) { return EMPTY_GROUPS; + } else { + try { + groups = resolvePartialGroupNames(user, e.getMessage(), + executor.getOutput()); + } catch (PartialGroupNameException pge) { + LOG.warn("unable to return groups for user {}", user, pge); + return EMPTY_GROUPS; + } } } catch (IOException ioe) { - // If its a shell executor timeout, indicate so in the message - // but treat the result as empty instead of throwing it up, - // similar to how partial resolution failures are handled above - if (executor.isTimedOut()) { - LOG.warn( - "Unable to return groups for user '{}' as shell group lookup " + - "command '{}' ran longer than the configured timeout limit of " + - "{} seconds.", - user, - Joiner.on(' ').join(executor.getExecString()), - timeout - ); + if (handleExecutorTimeout(executor, user)) { return EMPTY_GROUPS; } else { // If its not an executor timeout, we should let the caller handle it