Skip to content

Handle TLS errors instead of server aborting. #166

Closed

Description

@ringostarr80

Hi,

how can I handle TLS errors without aborting the server?

In the server-example https://github.com/rustls/hyper-rustls/blob/main/examples/server.rs, there is the following code-part:

let incoming_tls_stream = stream! {
    loop {
        let (socket, _) = tcp.accept().await?;
        let stream = tls_acceptor.accept(socket).map_err(|e| {
            println!("[!] Voluntary server halt due to client-connection error...");
            // Errors could be handled here, instead of server aborting.
            // Ok(None)
            error(format!("TLS Error: {:?}", e))
        });
        yield stream.await;
    }
};

In this code-fragment is a comment, that you can handle errors, instead of aborting the server. So I tried to uncomment the
Ok(None)
line and commented out the
error(format!("TLS Error: {:?}", e))
line.

But then I get the following compiler error:

error[E0277]: the trait bound `Result<std::option::Option<_>, _>: From<std::io::Error>` is not satisfied
   --> src/main.rs:164:31
    |
164 |       let incoming_tls_stream = stream! {
    |  _______________________________^
165 | |         loop {
166 | |             let (socket, _) = tcp.accept().await?;
167 | |             let stream = tls_acceptor.accept(socket).map_err(|e| {
...   |
175 | |         }
176 | |     };
    | |_____^ the trait `From<std::io::Error>` is not implemented for `Result<std::option::Option<_>, _>`
    |
    = help: the following implementations were found:
              <Result<(), idna::uts46::Errors> as From<idna::uts46::Errors>>
              <Result<(), ring::error::Unspecified> as From<ring::bssl::Result>>
              <Result<miniz_oxide::MZStatus, miniz_oxide::MZError> as From<&miniz_oxide::StreamResult>>
              <Result<miniz_oxide::MZStatus, miniz_oxide::MZError> as From<miniz_oxide::StreamResult>>
    = note: required because of the requirements on the impl of `Into<Result<std::option::Option<_>, _>>` for `std::io::Error`
    = note: this error originates in the macro `$crate::async_stream_impl::stream_inner` (in Nightly builds, run with -Z macro-backtrace for more info)

I think, it's obviously not the right way to replace error(...) against Ok(None).

But what is the right way?

Activity

  1. djc commented on Feb 11, 2022

    @djc
    Member

    Have a look at #147 for one example. I'm sorry I haven't yet had a chance to review/merge it.

  2. ringostarr80 commented on Feb 11, 2022

    @ringostarr80
    Author

    Ok, thanks. I will look at it.

  3. ringostarr80 commented on Feb 14, 2022

    @ringostarr80
    Author

    Ok, this works.

    Thanks.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions