My app is using VpnService for traffic interception.
What it does:
1.Reads from Tun device in a loop:
while (started && tunDevice.valid()) {
final byte[] bytes = tunDevice.read();
IpPacket packet = PacketFactory.createPacket(bytes);
if (packet == null) {
Thread.yield();
} else {
proxyService.handlePacket(packet);
}
}
TunDevice.read:
@Override
public byte[] read() throws IOException {
if (!valid()) {
LOG.warn("TUN: file descriptor is not valid any more");
return null;
}
int length = tunInputStream.read(readBuffer);
LOG.debug("TUN: Received packet length={}", length);
if (length < 0) {
throw new IOException("Tun device is closed");
}
if (length == 0) {
return null;
}
return Arrays.copyOfRange(readBuffer, 0, length);
}
2.Proxifies data to the protected socket.
The problem is that after some time it stops reading from TUN device. Read method just hangs and waits for some time (like 3-5 minutes).
Using netstat I see that all new connections are in SYN_SENT state and I can understand why - they cannot receive ACK from my code because I cannot receive these SYN packets.
The question is: what could it be? When TUN device could behave like this?