tokio-rs / tokio-tls

An implementation of TLS/SSL streams for Tokio
MIT License
95 stars 37 forks source link

TlsStream does not respect the `AsyncRead` / `AsyncWrite` contract #33

Closed carllerche closed 6 years ago

carllerche commented 7 years ago

Both AsyncRead and AsyncWrite except the same contract as poll. Aka, reading and writing should be possible to perform on separate tasks. tokio-io assumes this w/ split. However, TLS may perform writes in reads and reads in writes. If TLS's read and writes are performed in separate tasks, it is possible to break the contract and end up with dead locks.

As far as I can tell, there is only a single possible fix and that is notifying both the reader task AND the writer task when either the inner read or write half becomes ready. Doing so would probably require using with_notify to implement a "broadcast" notification strategy where both the outer read & write tasks get notified when either the inner read or write become ready.

There could be potential refinements in the heuristic, but the general strategy would be the same.

carllerche commented 6 years ago

Moved: https://github.com/tokio-rs/tokio/issues/532