Skip to content

Commit 89bc297

Browse files
committed
Ensure the OP_WRITE subscription can't get left on
Unclear how, but it seems that it is still possible for this to happen. Once it does, that channel spins 100% on the device until it closes, or until we successfully write something else (and clear up afterwards). Would be nice to find the root cause, but this solves the immediate problem safely & clearly.
1 parent 5b74ae8 commit 89bc297

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

app/src/main/java/tech/httptoolkit/android/vpn/socket/SocketNIODataService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ private void runTask(){
150150

151151
while (iterator.hasNext()) {
152152
SelectionKey key = iterator.next();
153-
SelectableChannel selectableChannel = key.channel();
154-
155153
Session session = ((Session) key.attachment());
156154
synchronized (session) { // Sessions are locked during processing (no VPN data races)
157155
try {
@@ -235,7 +233,10 @@ private void processSelectorRead(SelectionKey selectionKey, Session session) {
235233

236234
private void processPendingWrite(SelectionKey selectionKey, Session session) {
237235
// Nothing to write? Skip this entirely, and make sure we're not subscribed
238-
if (!session.hasDataToSend() || !session.isDataForSendingReady()) return;
236+
if (!session.hasDataToSend() || !session.isDataForSendingReady()) {
237+
session.unsubscribeKey(SelectionKey.OP_WRITE);
238+
return;
239+
}
239240

240241
boolean canWrite;
241242
synchronized (selectionKey) {

0 commit comments

Comments
 (0)