tokio-socks5 icon indicating copy to clipboard operation
tokio-socks5 copied to clipboard

high cpu usage in macOS

Open SerhoLiu opened this issue 6 years ago • 0 comments

Hi, I use the latest version in macOS 10.13, tokio-socks5 cpu usage is very high。

some log:

Listening for socks5 proxy connections on 127.0.0.1:8080
error for 127.0.0.1:58096: timeout during handshake
error for 127.0.0.1:58100: Connection reset by peer (os error 54)
error for 127.0.0.1:58101: Connection reset by peer (os error 54)
proxied 568/168 bytes for 127.0.0.1:58099
proxied 568/168 bytes for 127.0.0.1:58120
error for 127.0.0.1:58122: Socket is not connected (os error 57)
error for 127.0.0.1:58108: Connection reset by peer (os error 54)
error for 127.0.0.1:58127: timeout during handshake
error for 127.0.0.1:58128: timeout during handshake
error for 127.0.0.1:58134: timeout during handshake

connection may RST by firewall . use dtruss trace:

sudo dtruss -p 9794

recvfrom(0xB, 0x10EC82980, 0x10000)      = -1 Err#35
recvfrom(0x1B, 0x10EC82980, 0x10000)     = -1 Err#35
recvfrom(0x1A, 0x10EC82980, 0x10000)     = -1 Err#35
recvfrom(0xA, 0x10EC82980, 0x10000)	= -1 Err#35
recvfrom(0xE, 0x10EC82980, 0x10000)       = -1 Err#35
...
...

add some log in: https://github.com/tokio-rs/tokio-socks5/blob/master/src/main.rs#L557

println!("poll.......");

and https://github.com/tokio-rs/tokio-core/blob/master/src/net/tcp.rs#L344

if let Async::Ready(x) = r {
    println!("poll read {:?}", x)
 }

log output:

poll.......
poll read Hup
poll.......
poll read Hup
poll.......
poll read Hup
poll.......
poll read Hup
poll.......
poll read Hup
poll.......
poll read Hup
poll.......
poll read Hup
...
...

It looks like HUP, poll read and poll write both Ready but read returns WouldBlock.

let read_ready = self.reader.poll_read().is_ready();
let write_ready = self.writer.poll_write().is_ready();
if !read_ready || !write_ready {
    return Ok(Async::NotReady)
}

let n = try_nb!((&*self.reader).read(&mut buffer));

some help?

SerhoLiu avatar Jun 04 '18 11:06 SerhoLiu