Skip to content

TLS connections always get unexpected eof when the server closes the connection #673

Closed

Description

@ortuman

Summary

when using compio-tls with rustls, every server-initiated connection close results in the client receiving an unexpected eof while reading SSL error instead of a clean TLS shutdown. this happens on every close path (graceful server shutdown, protocol errors, authentication failures, etc.)

How to Reproduce

  1. Set up a compio-tls server using rustls.
  2. Connect with openssl s_client -connect <addr> -ign_eof.
  3. Trigger any server-side connection close
  4. The client reports:
error:0A000126:SSL routines::unexpected eof while reading:ssl/record/rec_layer_s3.c:696:

Expected: the connection closes cleanly with a TLS close_notify alert and no client-side error.

Suspicion

it looks like the TLS close_notify message is being buffered but never flushed before the underlying TCP connection is closed.

Versions

  • compio-io: 0.18.0
  • compio-tls: 0.9.0

Activity

  1. ortuman commented on Feb 11, 2026

    @ortuman
    ContributorAuthor

    here is a minimal TLS server snippet to reproduce the bug:

    use std::sync::Arc;
    
    use compio::net::TcpListener;
    use compio_io::{AsyncWrite, AsyncWriteExt};
    use compio_tls::TlsAcceptor;
    
    #[compio::main]
    async fn main() {
      rustls::crypto::ring::default_provider().install_default().unwrap();
    
      let cert = rcgen::generate_simple_self_signed(vec!["localhost".to_string()]).unwrap();
      let key = rustls::pki_types::PrivatePkcs8KeyDer::from(cert.key_pair.serialize_der());
      let cert = rustls::pki_types::CertificateDer::from(cert.cert);
    
      let config = rustls::ServerConfig::builder()
        .with_no_client_auth()
        .with_single_cert(vec![cert], key.into())
        .unwrap();
    
      let acceptor = TlsAcceptor::from(Arc::new(config));
      let listener = TcpListener::bind("127.0.0.1:8443").await.unwrap();
    
      println!("listening on 127.0.0.1:8443");
      println!("connect with: openssl s_client -connect 127.0.0.1:8443 -ign_eof");
    
      loop {
        let (stream, addr) = listener.accept().await.unwrap();
        println!("[{addr}] accepted");
    
        let acceptor = acceptor.clone();
    
        compio::runtime::spawn(async move {
          let mut tls_stream = acceptor.accept(stream).await.unwrap();
          println!("[{addr}] TLS handshake complete");
    
          // Write a message, then close the connection.
          // The TLS close_notify should be sent, but it never reaches the peer.
          tls_stream.write_all("hello\n".as_bytes().to_vec()).await.0.unwrap();
          tls_stream.flush().await.unwrap();
          tls_stream.shutdown().await.unwrap();
    
          println!("[{addr}] connection closed");
        })
        .detach();
      }
    }

    Cargo.toml

    [package]
    name = "tls-server"
    version = "0.1.0"
    edition = "2021"
    
    [dependencies]
    compio = { version = "0.18", features = ["net", "macros"] }
    compio-tls = { version = "0.9", features = ["rustls"] }
    compio-io = { version = "0.9" }
    rustls = { version = "0.23", features = ["ring"] }
    rcgen = "0.13"

    then do:

    openssl s_client -connect 127.0.0.1:8443 -ign_eof
    

    output:

    hello
    C062FE239B7F0000:error:0A000126:SSL routines::unexpected eof while reading:ssl/record/rec_layer_s3.c:696:
    
  2. Berrysoft commented on Feb 12, 2026

    @Berrysoft
    Member

    I can reproduce this issue.

  3. Berrysoft commented on Feb 13, 2026

    @Berrysoft
    Member

    compio-io 0.9.1 has been published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: tlsRelated to compio-tls

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions