sdrtrunk icon indicating copy to clipboard operation
sdrtrunk copied to clipboard

Broadcaster clear method not Thread Safe

Open DSheirer opened this issue 2 years ago • 2 comments

The broadcaster class is not protecting the clear() method's operation with the reentrant lock and this is causing issues.

Consider re-initializing the array list instead of clearning the existing array list, but protected by the reentrant lock.

DSheirer avatar May 20 '22 08:05 DSheirer

I suspect that this error was caused by the user trying to view the event history of a channel at the same time that the channel was being torn down which may have invoked the Broadcaster.clear() on another thread while this thread was attempting to view the history module content.

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 10 at java.base/java.util.ArrayList.fastRemove(Unknown Source) at java.base/java.util.ArrayList.remove(Unknown Source) at io.github.dsheirer.sample.Broadcaster.removeListener(Broadcaster.java:121) at io.github.dsheirer.module.HistoryModule.removeListener(HistoryModule.java:89) at io.github.dsheirer.module.decode.event.DecodeEventPanel.receive(DecodeEventPanel.java:146) at io.github.dsheirer.module.decode.event.DecodeEventPanel.receive(DecodeEventPanel.java:60) at io.github.dsheirer.sample.Broadcaster.broadcast(Broadcaster.java:151) at io.github.dsheirer.channel.metadata.ChannelMetadataPanel.valueChanged(ChannelMetadataPanel.java:182) at java.desktop/javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source) at java.desktop/javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source) at java.desktop/javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source) at java.desktop/javax.swing.DefaultListSelectionModel.removeIndexInterval(Unknown Source) at java.desktop/javax.swing.JTable.tableRowsDeleted(Unknown Source) at java.desktop/javax.swing.JTable.tableChanged(Unknown Source) at java.desktop/javax.swing.table.AbstractTableModel.fireTableChanged(Unknown Source) at java.desktop/javax.swing.table.AbstractTableModel.fireTableRowsDeleted(Unknown Source) at io.github.dsheirer.channel.metadata.ChannelMetadataModel.lambda$remove$2(ChannelMetadataModel.java:158) at java.desktop/java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.desktop/java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.desktop/java.awt.EventQueue$4.run(Unknown Source) at java.desktop/java.awt.EventQueue$4.run(Unknown Source) at java.base/java.security.AccessController.doPrivileged(Unknown Source) at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.desktop/java.awt.EventQueue.dispatchEvent(Unknown Source) at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.desktop/java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.desktop/java.awt.EventDispatchThread.run(Unknown Source)

DSheirer avatar May 20 '22 08:05 DSheirer

This method was previously protected by the reentrant lock and that caused issues. This change will need extensive testing.

DSheirer avatar May 20 '22 08:05 DSheirer

Resolved.

DSheirer avatar Jun 05 '23 11:06 DSheirer