Skip to content

Make accept of Transport cancel safe #84

@yujqiao

Description

@yujqiao

This is unlikely to occur. But if a hot-reload for a service and a TCP connection arrives at the same time, the TCP connection will be dropped.

https://github.com/rapiz1/rathole/blob/1240dd8df93d966e6c357ac67ffcecb6fcf0b1c4/src/server.rs#L140-L143

A primitive thought is to turn Transport::accept into Transport::handshake and make it accept a raw TCP connection. And use TCPListener::accept in select because it is cancel safe. However it breaks some abstraction and assumes the underlying protocol is TCP, which causes trouble for UDP-based transport, like QUIC. So maybe the trait can be redesigned in another way. Thoughts will be welcome.

Or keep the trait unchanged and write a future to make Transport::accept cancel safe. I don't know if that's feasible. For TCP, it's impossible to put an accepted connection back to the system backlog. And generally handshake consists of multiple packets. I doubt it can made cancel safe without altering the trait. Redesigning the trait seems the way to go.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdesignDesign discussion needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions