mirror of
https://github.com/sbt/sbt.git
synced 2026-09-01 02:27:13 +02:00
Use ConcurrentLinkedDeque for EventHandler
ArrayList::add is not thread safe. I ran into cases where async tests using utests would fail even when all of the individual tests passed. This was because multiple threads called back into the handle method of the handler instance variable, which just delegated to eventList::add. When this happened, one of the events would get added to the list as a null reference, which would manifest as an NPE upstream on the master process. After this change, my tests stopped failing.
This commit is contained in:
@@ -17,6 +17,7 @@ import java.net.Socket;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
@@ -294,7 +295,7 @@ final public class ForkMain {
|
||||
Task[] nestedTasks;
|
||||
final TaskDef taskDef = task.taskDef();
|
||||
try {
|
||||
final List<ForkEvent> eventList = new ArrayList<ForkEvent>();
|
||||
final Collection<ForkEvent> eventList = new ConcurrentLinkedDeque<ForkEvent>();
|
||||
final EventHandler handler = new EventHandler() { public void handle(final Event e){ eventList.add(new ForkEvent(e)); } };
|
||||
logDebug(os, " Running " + taskDef);
|
||||
nestedTasks = task.execute(handler, loggers);
|
||||
|
||||
Reference in New Issue
Block a user