-
Notifications
You must be signed in to change notification settings - Fork 125
fix(mixed): prevent listener from exiting on socket peek failure (os error 10054) #823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
14297e8
58a61ef
1b4e2a3
390aee6
0b4b8bb
28d1d95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,16 +57,37 @@ impl InboundHandlerTrait for MixedInbound { | |
| let listener = TcpListener::bind(self.addr).await?; | ||
|
|
||
| loop { | ||
| let (socket, _) = listener.accept().await?; | ||
| let src_addr = socket.peer_addr()?; | ||
| let (socket, _) = match listener.accept().await { | ||
| Ok(s) => s, | ||
| Err(e) => { | ||
| warn!("failed to accept socket on {}: {:?}", self.addr, e); | ||
| continue; | ||
| } | ||
| }; | ||
| let src_addr = match socket.peer_addr() { | ||
| Ok(a) => a, | ||
| Err(e) => { | ||
| warn!("failed to get peer address: {:?}", e); | ||
| continue; | ||
| } | ||
| }; | ||
| if !self.allow_lan && src_addr.ip() != socket.local_addr()?.ip() { | ||
| warn!("Connection from {} is not allowed", src_addr); | ||
| continue; | ||
| } | ||
| apply_tcp_options(&socket)?; | ||
|
|
||
| let mut p = [0; 1]; | ||
| let n = socket.peek(&mut p).await?; | ||
| let n = match socket.peek(&mut p).await { | ||
| Ok(n) => n, | ||
| Err(e) => { | ||
| warn!( | ||
| "failed to peek socket on mixed listener {}: {:?}", | ||
| self.addr, e | ||
| ); | ||
| continue; | ||
| } | ||
| }; | ||
| if n != 1 { | ||
| warn!("failed to peek socket on mixed listener {}", self.addr); | ||
| continue; | ||
|
|
@@ -98,14 +119,19 @@ impl InboundHandlerTrait for MixedInbound { | |
|
|
||
| _ => { | ||
| let src = socket.peer_addr()?; | ||
| http::handle_http( | ||
| Box::new(socket), | ||
| src, | ||
| dispatcher, | ||
| authenticator, | ||
| fw_mark, | ||
| ) | ||
| .await; | ||
| let dispatcher = dispatcher.clone(); | ||
| let authenticator = authenticator.clone(); | ||
| let fw_mark = fw_mark; | ||
| tokio::spawn(async move { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the handle_http is already a spawn, maybe change the signature to sync and no need to spawn again here.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or remote the spawn in handle_http to be consistent with the socks handle
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| http::handle_http( | ||
| Box::new(socket), | ||
| src, | ||
| dispatcher, | ||
| authenticator, | ||
| fw_mark, | ||
| ) | ||
| .await; | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -114,4 +140,4 @@ impl InboundHandlerTrait for MixedInbound { | |
| async fn listen_udp(&self) -> std::io::Result<()> { | ||
| Err(new_io_error("UDP is not supported")) | ||
| } | ||
| } | ||
| } | ||
ibigbug marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.