DataWriter.flush(); circuit.terminate(); does not behave as one would expect (race condition?)
Related to my investigation working around #1368 (which is arguably fine but weird).
So as mentioned there, I have pumps that forward traffic back and forth between arti DataStream
s and tokio::TcpStream
s.
The behaviour I'm seeing is that data that has been sent from one instance, whose circuit is subsequently killed, never makes it across the wire to another arti (or tor) instance.
The simplified flow is roughly:
let mut buf = [0u8; 1024];
let count = tcp_stream.read(&mut buff).unwrap();
data_stream.write_all(&buf[0..count]);
data_stream.flush();
circuit.terminate();
Frequently, the receiving data_stream.read(..)
call returns an error:
Custom { kind: InvalidData, error: StreamProto("stream channel disappeared without END cell?") }
Fun fact, if you insert a std::thread::sleep()
of a few seconds in-between the data_stream.flush()
and the circuit.terminate()
you can reliably trigger the above behaviour. If you insert a tokio::time::sleep().await
instead then whatever's happening in the background has enough time to do whatever it's doing to send the flush()
'd data!