Opened 9 years ago

Closed 9 years ago

#388 closed defect (fixed)

I2PThread and I2PAppThread not thread safe

Reported by: John Doo Owned by: zzz
Priority: minor Milestone: 0.8.4
Component: api/utils Version: 0.8.2
Keywords: Cc:
Parent Tickets: Sensitive: no

Description

I2PThread and I2PAppThread both use a HashSet? for _listeners and _threadListeners respectively without further synchronisation. This can cause a ConcurrentModificationException? if a listener is added or removed while fireOOM iterates over this set.
Solution: java.util.concurrent.CopyOnWriteArraySet?

In I2PThread obtaining a log-instance in

private void log(int level, String msg, Throwable t){

if (log == null) _log = new Log(I2PThread.class);…}

is not thread safe as well.
The check-then-act needs to be synchronized.

Another solution is the "Lazy initialization holder class idiom.":

private static class LogHolder? {

public static Log log = new Log(I2PThread.class);

}

and

private void log(int level, String msg, Throwable t){

if (log == null) _log = new Log(I2PThread.class);…}

Subtickets

Change History (3)

comment:1 Changed 9 years ago by Eche|on

Milestone: 0.8.3
Owner: set to zzz
Status: newassigned

comment:2 Changed 9 years ago by zzz

Milestone: 0.8.30.8.4
Priority: majorminor
Status: assignedaccepted

Switched to COWAS, in test4 branch, to be in 0.8.4

comment:3 Changed 9 years ago by zzz

Resolution: fixed
Status: acceptedclosed
Note: See TracTickets for help on using tickets.