[ 
https://issues.apache.org/jira/browse/LOG4J2-3452?focusedWorklogId=894753&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-894753
 ]

ASF GitHub Bot logged work on LOG4J2-3452:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 08/Dec/23 16:55
            Start Date: 08/Dec/23 16:55
    Worklog Time Spent: 10m 
      Work Description: merkisoft commented on PR #809:
URL: https://github.com/apache/logging-log4j2/pull/809#issuecomment-1847522126

   the problem is that althought the logs dir exists, you call to create it and 
java security manager kicks in and it requires these two lines (i only had the 
2nd initially, because in my view log4j should not attempt to write the dir):
   
       permission java.io.FilePermission "${user.dir}/logs", "read,write";    
//  <<< this was missing and grants mkdir on the parent
       permission java.io.FilePermission "${user.dir}/logs/-", "read,write";
   
   config - using log4j 1-2 bridge:
   log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
   log4j.appender.file.File=logs/kurs.log
   
   anyhow: the java security manager / policy files are not often used and are 
apparently on the way out, no need to fix - hopefully the one who has the same 
issue finds this comment :-)




Issue Time Tracking
-------------------

    Worklog Id:     (was: 894753)
    Time Spent: 0.5h  (was: 20m)

> Race condition in FileUtils.mkdir()
> -----------------------------------
>
>                 Key: LOG4J2-3452
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3452
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.13.0
>            Reporter: Stefan Vodita
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> I noticed an error like:
> {{ERROR Unable to create file ...}}
> {{at org.apache.logging.log4j.core.util.FileUtils.mkdir(FileUtils.java:118)}}
>  
> The error could be due to a race condition:
> {{Thread A: dir.exists() -> false}}
> {{Thread B: dir.exists() -> false}}
> {{Thread B: dir.mkdirs() -> succeeds}}
> {{Thread A: dir.mkdirs() -> throws exception}}
>  
> I wrote a unit test which reproduces the error:
> {{public void testMkdirConcurrent() throws IOException {}}
> {{        final File file = new File("target/test/test");}}
> {{        for (int i = 0; i < 1000; i++) {}}
> {{            new Thread(() -> assertDoesNotThrow(() -> FileUtils.mkdir(file, 
> true))).start();}}
> {{        org.apache.commons.io.FileUtils.deleteDirectory(file);}}
> {{}}}
>  
> As a fix, we can use {{{}Files.createDirectories(){}}}, since this does the 
> existence check and creation as one atomic operation.
>  
> I will create a PR with the unit test and a fix.
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to