Commit 5deb206b authored by Mygod's avatar Mygod

Handle IOException while reading

parent 06c46d30
...@@ -4,6 +4,7 @@ import android.net.LocalSocket ...@@ -4,6 +4,7 @@ import android.net.LocalSocket
import com.github.shadowsocks.Core import com.github.shadowsocks.Core
import com.github.shadowsocks.net.ConcurrentLocalSocketListener import com.github.shadowsocks.net.ConcurrentLocalSocketListener
import com.github.shadowsocks.net.DnsResolverCompat import com.github.shadowsocks.net.DnsResolverCompat
import com.github.shadowsocks.utils.readableMessage
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.TimeoutCancellationException import kotlinx.coroutines.TimeoutCancellationException
...@@ -23,8 +24,11 @@ class LocalDnsWorker(private val resolver: suspend (ByteArray) -> ByteArray) : C ...@@ -23,8 +24,11 @@ class LocalDnsWorker(private val resolver: suspend (ByteArray) -> ByteArray) : C
launch { launch {
socket.use { socket.use {
val input = DataInputStream(socket.inputStream) val input = DataInputStream(socket.inputStream)
val query = ByteArray(input.readUnsignedShort()) val query = try {
input.read(query) ByteArray(input.readUnsignedShort()).also { input.read(it) }
} catch (e: IOException) { // connection early close possibly due to resolving timeout
return@use Timber.d(e)
}
try { try {
resolver(query) resolver(query)
} catch (e: Exception) { } catch (e: Exception) {
...@@ -46,7 +50,9 @@ class LocalDnsWorker(private val resolver: suspend (ByteArray) -> ByteArray) : C ...@@ -46,7 +50,9 @@ class LocalDnsWorker(private val resolver: suspend (ByteArray) -> ByteArray) : C
val output = DataOutputStream(socket.outputStream) val output = DataOutputStream(socket.outputStream)
output.writeShort(response.size) output.writeShort(response.size)
output.write(response) output.write(response)
} catch (_: IOException) { } // connection early close possibly due to resolving timeout } catch (e: IOException) {
Timber.d(e.readableMessage)
}
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment