Skip to content

[bug] x86_64: basic TCP test cannot establish connection #129

@sunhaosheng

Description

@sunhaosheng

Describe the bug

On the x86_64 architecture, a basic TCP echo test cannot establish a connection between a host-side client and a server running inside the system.

The client reports Connected to server, but no actual data exchange happens:

  • the server only prints that it is listening on 0.0.0.0:5555
  • the server never reports an accepted client connection
  • the client blocks after connecting and does not receive the echoed message

In addition, the server process cannot be terminated with Ctrl+C.

To Reproduce

  1. Build and run the following TCP echo server inside the system:
use std::io::{Read, Write};
use std::net::{TcpListener, TcpStream};
use std::thread;

fn handle_client(mut stream: TcpStream) {
    println!("Client connected: {:?}", stream.peer_addr());

    let mut buf = [0u8; 1024];

    loop {
        match stream.read(&mut buf) {
            Ok(0) => {
                println!("Client disconnected");
                break;
            }
            Ok(n) => {
                println!("Received: {}", String::from_utf8_lossy(&buf[..n]));
                stream.write_all(&buf[..n]).unwrap();
            }
            Err(e) => {
                println!("Read error: {:?}", e);
                break;
            }
        }
    }
}

fn main() {
    let listener = TcpListener::bind("0.0.0.0:5555").expect("bind failed");

    println!("Server listening on 0.0.0.0:5555");

    for stream in listener.incoming() {
        match stream {
            Ok(stream) => {
                thread::spawn(|| handle_client(stream));
            }
            Err(e) => {
                println!("Connection failed: {:?}", e);
            }
        }
    }
}
  1. Build and run the following client on the host side:
use std::io::{Read, Write};
use std::net::TcpStream;

fn main() {
    let mut stream =
        TcpStream::connect("127.0.0.1:5555").expect("connect failed");

    println!("Connected to server");

    let msg = b"hello from host!";
    stream.write_all(msg).unwrap();

    let mut buf = [0u8; 1024];
    let n = stream.read(&mut buf).unwrap();

    println!("Echo back: {}", String::from_utf8_lossy(&buf[..n]));
}
  1. Observe the runtime behavior on both sides.

Expected behavior

The client should successfully connect to the server, send "hello from host!", and receive the same message back.

The server should print logs similar to:

  • Client connected: ...
  • Received: hello from host!

Also, the server process should be terminable with Ctrl+C.

Screenshots

Not applicable.

Environment

  • Architecture: x86_64
  • Test scenario: host-side TCP client connecting to a TCP server running inside the system
  • Server bind address: 0.0.0.0:5555
  • Client connect address: 127.0.0.1:5555

Additional context

This is a very basic TCP echo test case, so it seems that fundamental TCP connection handling may not be working correctly on x86_64 in this scenario.

Another abnormal behavior is that the server process cannot be killed with Ctrl+C, which may indicate an additional issue related to signal handling or blocking behavior.

Logs

Client side:

~/test-for-tcp/client$ cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
     Running `target/debug/client`
Connected to server

Server side:

starry:~# /usr/bin/server
Server listening on 0.0.0.0:5555

Observed result:

  • the client and server do not complete the TCP echo interaction
  • the server never prints a client connection message
  • the server cannot be terminated with Ctrl+C

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions