Skip to content

Conversation

@TingDaoK
Copy link
Contributor

@TingDaoK TingDaoK commented May 5, 2020

Issue #, if available:

  • Used FIFO cache to store the closed streams.
  • Remove streams closed from the closed stream cache, once the cache is full.
  • Fixed different type of error we report at closed state of stream. Details are as followed:
  1. Receive RST_STREAM, then receive frames soon after: stream error of type STREAM_CLOSED
  2. Receive END_STREAM, then receive WINDOW_UPDATE and RST_STREAM soon after: ignore frames
  3. Receive END_STREAM, then receive frames other than WINDOW_UPDATE and RST_STREAM soon after: connection error of type STREAM_CLOSED
  4. Send RST_STREAM, then receive frames soon after: ignore frames
  5. Stream closed loooong ago, then receive any frames: connection error of type
    PROTOCOL_ERROR

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@TingDaoK TingDaoK marked this pull request as ready for review May 5, 2020 23:07
@TingDaoK TingDaoK changed the title Remove stream closed long ago from closed stream structure Remove streams closed long ago from closed stream structure May 5, 2020
#define AWS_H2_MIN_WINDOW_SIZE (256)
/* We will ignore frames for closed stream within this time slot, after that we will treat them as connection error:
* nano secs, 100000000 nano secs -> 0.1 sec */
#define AWS_H2_IGNORE_TIME (100000000)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know how long it should be, and the spec seems let us make our own choice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should see if we can get some inspiration from other H2 implementations, check node's or chrome's maybe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming/comment suggestion "ignore time" is just too vague. Also, the frames aren't always ignored, they can cause stream errors too

/* Once a stream is closed, the connection remembers details about it for this long.
 * After that, the details are cleaned up and any frames that arrive for the stream
 * are treated as a connection error. */
AWS_H2_CLOSED_STREAM_MEMORY_TIME

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I looked into Netty and Nghttp2 to see how they deal with the close stream. And they both not exactly follow the spec to define a time slot for ignoring the frame...🤦‍ And Chrome is just too complicated...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used LRU cache instead of a fixed time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, one possible case? Someone open a lot of streams and keep sending RST_STREAM on them, the LRU cache will keep those closed streams as MRU, and the other recently closed stream will be kept out of the cache, and we will result in treating all the others as connection error.🤦‍And we will keep sending RST_STREAM back...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finially, FIFO cache instead of LRU cache!

@TingDaoK TingDaoK requested a review from a team May 5, 2020 23:12
Copy link
Contributor

@justinboswell justinboswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally, looks pretty good, just a few naming/clarity things

#define AWS_H2_MIN_WINDOW_SIZE (256)
/* We will ignore frames for closed stream within this time slot, after that we will treat them as connection error:
* nano secs, 100000000 nano secs -> 0.1 sec */
#define AWS_H2_IGNORE_TIME (100000000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should see if we can get some inspiration from other H2 implementations, check node's or chrome's maybe?

#define AWS_H2_MIN_WINDOW_SIZE (256)
/* We will ignore frames for closed stream within this time slot, after that we will treat them as connection error:
* nano secs, 100000000 nano secs -> 0.1 sec */
#define AWS_H2_IGNORE_TIME (100000000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming/comment suggestion "ignore time" is just too vague. Also, the frames aren't always ignored, they can cause stream errors too

/* Once a stream is closed, the connection remembers details about it for this long.
 * After that, the details are cleaned up and any frames that arrive for the stream
 * are treated as a connection error. */
AWS_H2_CLOSED_STREAM_MEMORY_TIME

TingDaoK and others added 4 commits May 11, 2020 11:26
…ure' of github.com:awslabs/aws-c-http into remove-stream-closed-long-ago-from-closed-stream-structure
Copy link
Contributor

@graebm graebm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix & ship

/* When window size is too small to fit the possible padding into it, we stop sending data and wait for WINDOW_UPDATE */
#define AWS_H2_MIN_WINDOW_SIZE (256)
/* Default value for thread_data.max_closed_stream_cache_size */
#define AWS_H2_DEFAULT_MAX_CACHE_SIZE (32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming suggestion: AWS_H2_DEFAULT_MAX_CLOSED_STREAMS
"cache" is pretty vague unless you know the code

also, the comment refers to a variable that doesn't exist anymore

* MUST treat that as a stream error (Section 5.4.2) of type STREAM_CLOSED */

/* Stream was closed long ago, or didn't fit criteria for being ignored */
/* Stream was closed long ago (or implicitly closed when its ID was skipped) */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial: "long ago" doesn't really apply anymore

/* Stream closed (purged from closed_streams, or implicitly closed when its ID was skipped) */

@TingDaoK TingDaoK merged commit 5863e8d into master May 11, 2020
@TingDaoK TingDaoK deleted the remove-stream-closed-long-ago-from-closed-stream-structure branch May 11, 2020 20:27
czakian pushed a commit to czakian/aws-c-http that referenced this pull request May 12, 2020
- Used FIFO cache to store the closed streams.
- Remove streams closed from the closed stream cache, once the cache is full.
- Fixed different type of error we report at closed state of stream. Details are as followed:
1. Receive RST_STREAM, then receive frames soon after: stream error of type STREAM_CLOSED
2. Receive END_STREAM, then receive WINDOW_UPDATE and RST_STREAM soon after: ignore frames
3. Receive END_STREAM, then receive frames other than WINDOW_UPDATE and RST_STREAM soon after: connection error of type STREAM_CLOSED
4. Send RST_STREAM, then receive frames soon after: ignore frames
5. Stream closed loooong ago, then receive any frames: connection error of type 
    PROTOCOL_ERROR

Co-authored-by: Dengke Tang <dengket@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants