Closed TimonPost closed 2 years ago
Not related to this issue, but a question I had regarding a note in this code in on_stream_frame
:
// Notifying about the opening of locally-initiated streams would be redundant.
However, if stream.initiator() == self.side
checks if initiated stream is created on the local endpoint side
. So why, if this is redundant, is this code still queuing the Readable
event? I am probably misinterpreting this comment or code so that's why I ask what I am missing?
I agree that the documentation here is unclear. We should not generate Readable
events for every Opened
event, because that adds no extra information. We could instead generate Readable
events more precisely (i.e. guarantee that a read operation will not be blocked), but it's unclear to me if this is worth the effort. Hence I think the best solution is to document that Opened
implies Readable
, and replace "has data or errors" with "may have data or errors" to communicate that false positives are permitted.
why, if this is redundant, is this code still queuing the Readable event
Because the Readable
event notifies about a stream becoming readable. As the comment indicates, only notifying about the opening of a locally-initiated stream would be redundant. An application inherently knows whether it has opened a locally initiated stream or not, but relies on events to determine when such a stream is readable.
I think this was fixed in #1284.
Given the following events:
Event::Readable // One or more new streams has been opened
Event::Opened // A currently open stream has data or errors waiting to be read
Readable
is generated inStreamState::on_stream_frame
The flag for
opened
streams is also set here. This means that when we process an incoming frame it either marks an opening stream or a readable event. While, as a user, I would expect both anOpened
andReadable
event when I receive data 'and' a stream is opened in the same packet.Why should we care When creating an FFI, or implementation of
quinn-proto
it can be confusing as one assumes to receive aReadable
event when data isReadable
. But instead, data could be ready to be read onOpened
event as well.Solutions:
Opened
could meanReadable
Readable
event whenstream.index() >= *next
. TheStreamState::poll
first processes any opened events, then later it processes other events. So this could be done without impacting the code too much. Tho it might be a false positive. But would a false positive be better than nothing at all?