Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/61#discussion_r14806843
  
    --- Diff: utils/common/src/main/java/brooklyn/util/os/Os.java ---
    @@ -544,13 +545,23 @@ public static File newTempFile(Class<?> clazz, String 
ext) {
     
         /** creates a temp dir which will be deleted on exit */
         public static File newTempDir(String prefix) {
    -        String baseName = (prefix==null ? "" : prefix + "-") + 
Identifiers.makeRandomId(4);
    -        File tempDir = new File(tmp(), baseName);
    -        if (tempDir.mkdir()) {
    -            Os.deleteOnExitRecursively(tempDir);
    -            return tempDir;
    +        String sanitizedPrefix = (prefix==null ? "" : prefix + "-");
    +        String tmpParent = tmp();
    +        for (int i = 0; i < TEMP_DIR_ATTEMPTS; i++) {
    +            String baseName = sanitizedPrefix + 
Identifiers.makeRandomId(4);
    +            File tempDir = new File(tmpParent, baseName);
    +            if (!tempDir.exists()) {
    +                if (tempDir.mkdir()) {
    +                    Os.deleteOnExitRecursively(tempDir);
    +                    return tempDir;
    +                } else {
    +                    log.warn("Attempt to create temp dir failed " + 
tempDir);
    +                }
    +            } else {
    +                log.debug("Attemp to create temp dir failed, already 
exists " + tempDir);
    --- End diff --
    
    have worked through the math.  it's the old "how many people in a room 
until there's a better than even chance two have the same birthday" problem.  
suggest the comment on the `debug` explain this, that with random id of length 
4 it's not unusual to have duplicates at the 2000 members mark.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to