You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by "Ralph Goers (JIRA)" <ji...@apache.org> on 2017/06/08 06:45:18 UTC

[jira] [Commented] (LOG4J2-1894) Potential data race in ReconfigurationDeadlockTest

    [ https://issues.apache.org/jira/browse/LOG4J2-1894?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16042293#comment-16042293 ] 

Ralph Goers commented on LOG4J2-1894:
-------------------------------------

There is a race here but it is accounted for by the loop.  However, I am noticing that the boolean values are not volatile so the changes might not be noticed. The array probably needs to be an array of AtomicBoolean values instead.

> Potential data race in ReconfigurationDeadlockTest
> --------------------------------------------------
>
>                 Key: LOG4J2-1894
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1894
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.8.1
>         Environment: Win10、java8
>            Reporter: yangxin
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> In this junit test ,  for the object *finished* , if  read (in method testReconfig ) is before  write ( in  method LoggerThread ), then the program will think the loggerThread didn't finish and print error message, but the loggerThread has finished in fact. If there is a potential data race?
> {code:title=ReconfigurationDeadlockTest.java|borderStyle=solid}
>  LoggerThread[] threads = new LoggerThread[THREAD_COUNT];
>     @Test
>     public void testReconfig() throws InterruptedException {
>         final Updater updater = new Updater();
>         for (int i = 0; i < THREAD_COUNT; ++i) {
>             threads[i] = new LoggerThread(i);
>             threads[i].setDaemon(true);
>         }
>         for (int i = 0; i < THREAD_COUNT; ++i) {
>             threads[i].start();
>         }
>         updater.setDaemon(true);
>         updater.start();
>         Thread.sleep(100);
>         boolean stillWaiting = true;
>         for (int i = 0; i < 200; ++i) {
>             int index = 0;
>             for (; index < THREAD_COUNT; ++index) {
>                 if (!finished[index]) {
>                     break;
>                 }
>             }
>             if (index == THREAD_COUNT) {
>                 stillWaiting = false;
>                 break;
>             }
>             Thread.sleep(100);
>         }
>         updater.shutdown = true;
>         if (stillWaiting) {
>             final ThreadDumpMessage message = new ThreadDumpMessage("Waiting");
>             System.err.print(message.getFormattedMessage());
>         }
>         for (int i = 0; i < THREAD_COUNT; ++i) {
>             if (threads[i].isAlive()) {
>                 threads[i].interrupt();
>             }
>         }
>         assertFalse("loggerThread didn't finish", stillWaiting);
>     }
>     private class LoggerThread extends Thread {
>         private final Logger logger = LogManager.getRootLogger();
>         private final int index;
>         public LoggerThread(final int i) {
>             index = i;
>         }
>         @Override
>         public void run() {
>             int i = 0;
>             try {
>                 for (i=0; i < 30; ++i) {
>                     logger.error("Thread: " + index + ", Test: " + i++);
>                 }
>             } catch (final Exception ie) {
>                 return;
>             }
>             finished[index] = true;
>         }
>     }
> {code}
>    



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)