From 4b2bfc87f97764fbb60ab3a69a61dd0a7e09520c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kohlschu=CC=88tter?= Date: Thu, 9 Nov 2023 15:02:41 +0100 Subject: [PATCH] Revert "Fix concurrency issue from modifying the selectedKeysSet" This reverts commit b8386a1d8391ffb4402edb1e1f0a070606debdb5. --- .../org/newsclub/net/unix/AFSelectionKey.java | 6 ++---- .../org/newsclub/net/unix/AFSelector.java | 19 ------------------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSelectionKey.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSelectionKey.java index 9f615dfbd..e5db4dc2d 100644 --- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSelectionKey.java +++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSelectionKey.java @@ -80,10 +80,8 @@ boolean isSelected() { @Override public void cancel() { - if (!cancelled.compareAndSet(false, true) || !chann.isOpen()) { - return; - } - sel.prepareRemove(this); + sel.remove(this); + cancelNoRemove(); } void cancelNoRemove() { diff --git a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSelector.java b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSelector.java index fedfab7b1..433aac740 100644 --- a/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSelector.java +++ b/junixsocket-common/src/main/java/org/newsclub/net/unix/AFSelector.java @@ -49,7 +49,6 @@ final class AFSelector extends AbstractSelector { private final Set selectedKeysSet = new HashSet<>(); private final Set selectedKeysPublic = new UngrowableSet<>(selectedKeysSet); - private final Set cancelledKeysSet = new HashSet<>(); private PollFd pollFd = null; @@ -113,7 +112,6 @@ private int select0(int timeout) throws IOException { throw new ClosedSelectorException(); } pfd = pollFd = initPollFd(pollFd); - performRemove(); selectedKeysSet.clear(); } int num; @@ -301,23 +299,6 @@ synchronized void remove(AFSelectionKey key) { pollFd = null; } - void prepareRemove(AFSelectionKey key) { - synchronized (cancelledKeysSet) { - cancelledKeysSet.add(key); - } - } - - void performRemove() { - synchronized (cancelledKeysSet) { - for (SelectionKey key : cancelledKeysSet) { - selectedKeysSet.remove(key); - deregister((AFSelectionKey) key); - pollFd = null; - } - cancelledKeysSet.clear(); - } - } - private void deregister(AFSelectionKey key) { // super.deregister unnecessarily casts SelectionKey to AbstractSelectionKey, and // ((AbstractSelectableChannel)key.channel()).removeKey(key); is not visible.