Skip to content
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

IpstackTcpStream::shutdown always Pending after read is cancelled #28

Closed
xmh0511 opened this issue Mar 27, 2024 · 1 comment
Closed

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Mar 27, 2024

This issue is the second issue in #27. The complete minimum reproductive example is

use std::sync::mpsc::channel;
use ipstack::stream::IpStackStream;
use tokio::io::{AsyncReadExt, AsyncWriteExt};

use tun2::{self, Configuration};
#[tokio::main]
async fn main() {
	let (tx, rx) = channel();
    let _ = ctrlc2::set_handler(move || {
        tx.send(()).expect("Could not send signal on channel.");
        true
    })
    .expect("Error setting Ctrl-C handler");

	let mut config = Configuration::default();
    config
        .address((10, 0, 0, 9))
        .netmask((255, 255, 255, 0))
        //.destination((10, 0, 0, 1))
        .tun_name("utun6")
        .up();
    let mut ipstack_config = ipstack::IpStackConfig::default();
    ipstack_config.mtu(u16::MAX);

    let mut ip_stack =
        ipstack::IpStack::new(ipstack_config, tun2::create_as_async(&config).unwrap());

		tokio::spawn(async move {
			while let Ok(stream) = ip_stack.accept().await {
				match stream {
					IpStackStream::Tcp(mut tcp) => {
						println!("IpStackStream::Tcp(tcp) {} -> {}", tcp.local_addr(), tcp.peer_addr());
						tokio::spawn(async move {
							let mut buff = [0u8;1500];
							loop{
								match tokio::time::timeout(std::time::Duration::from_secs(2),tcp.read(& mut buff)).await{
									Ok(_v)=>{
										//tcp.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n").await;
									}
									Err(_e)=>{
										println!("prepare to shutdown!!!!");
										tcp.shutdown().await.unwrap();
										println!("done!!!!");
										return;
									}
								};
							}
						});
					}
					_=>{}
				}
			}
		});
		rx.recv().expect("Could not receive from channel.");

		println!("terminate the program");
}

Running command curl http://10.0.0.2:6, and in this example, "done!!!!" will never be printed out.

IpStackStream::Tcp(tcp) 10.0.0.9:62559 -> 10.0.0.2:6
prepare to shutdown!!!!
SajjadPourali added a commit that referenced this issue Mar 27, 2024
SajjadPourali added a commit that referenced this issue Mar 28, 2024
* Fix #27 #28

* Fix the dependency issue

* Fix the uninitialized buffer during shutdown

* Remove unnecessary async function

* Fix the block when invalid packet received

* Fix the block when invalid packet received

* Remove the test file
@SajjadPourali
Copy link
Collaborator

Fixed on #30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants