643 Commits

Author SHA1 Message Date
Geoffry Song
571bb14556 Be more lenient with streams in the pending_send queue. (#261)
The `is_peer_reset()` check doesn't quite cover all the cases where we call
`clear_queue`, such as when we call `recv_err`. Instead of trying to make the
check more precise, let's gracefully handle spurious entries in the queue.
2018-05-09 20:01:39 -07:00
Carl Lerche
cf62b783e0 Misc bug fixes related to stream state (#273)
This patch includes two new significant debug assertions:

* Assert stream counts are zero when the connection finalizes.
* Assert all stream state has been released when the connection is 
  dropped.

These two assertions were added in an effort to test the fix provided
by #261. In doing so, many related bugs have been discovered and fixed.
The details related to these bugs can be found in #273.
2018-05-09 15:03:21 -07:00
Carl Lerche
b4383b6a8c Add more stream state tests (#271) 2018-05-04 14:11:40 -07:00
Carl Lerche
8a9dfd14dc Move tests and support utilities to sub crates. (#268)
These crates will not be published to crates.io, but moving them allows
`tower-h2` to also depend on the test utilities.
2018-05-03 13:08:39 -07:00
Dirkjan Ochtman
51f6a12454 Fix links to handshake() documentation (#265) 2018-04-30 10:32:39 -07:00
Sean McArthur
e8fcd34476 change from deprecated Buf::put_*<E> to put_*_be (#267) 2018-04-27 14:35:28 -07:00
Sean McArthur
fadec67fdf prevent a leak of 'active streams' if client request has user error (#266) 2018-04-26 18:20:32 -07:00
Carl Lerche
279dd93354 Bump version to v0.1.6 (#264) 2018-04-24 20:47:17 -07:00
Geoffry Song
558e6b6e6c Avoid reclaiming frames for dead streams. (#262)
In `clear_queue` we drop all the queued frames for a stream, but this doesn't
take into account a buffered frame inside of the `FramedWrite`. This can lead
to a panic when `reclaim_frame` tries to recover a frame onto a stream that has
already been destroyed, or in general cause wrong behaviour.

Instead, let's keep track of what frame is currently in-flight; then, when we
`clear_queue` a stream with an in-flight data frame, mark the frame to be
dropped instead of reclaimed.
2018-04-24 16:52:24 -07:00
Geoffry Song
11f914150e Add some missing bounds checks. (#260) 2018-04-23 14:38:42 -07:00
Eliza Weisman
040f391479 Reset any queued stream on receipt of remote reset (#258)
Fixes #256.

This PR changes `state::recv_reset` so any closed stream with queued send is immediately reset (and thus, the queue is cleared) on receipt of a `RST_STREAM` frame from the remote. 

This fixes the panic encountered by the test @goffrie posted in #256, where the stream is scheduled to close, receives a `RST_STREAM` frame, and sets the buffered capacity to 0, but isn't removed from the send queue, so we hit an assertion (or wrap, if debug assertions are disabled) when subtracting a sent frame's size from the buffered size.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2018-04-16 16:17:29 -07:00
Oliver Gould
fabae35311 Bump version to v0.1.5 (#255) 2018-04-06 18:41:27 -07:00
Sean McArthur
dca336f8b2 send proper max stream ID in graceful goaway (#254) 2018-04-06 15:51:34 -07:00
Sean McArthur
60749db680 Bump version to v0.1.4 2018-04-05 13:13:26 -07:00
Sean McArthur
65f69a3062 add ability to synchronize in tests
- Adds `wait_for` that takes another future to signal the mock
  should continue.
- Adds `yield_once` to allow one chain of futures to yield to the
  other.
2018-03-29 13:51:30 -07:00
Sean McArthur
1c5d4ded50 Add Graceful Shutdown support
If graceful shutdown is initiated, a GOAWAY of the max stream ID - 1 is
sent, followed by a PING frame, to measure RTT. When the PING is ACKed,
the connection sends a new GOAWAY with the proper last processed stream
ID. From there, once all active streams have completely, the connection
will finally close.
2018-03-29 13:51:30 -07:00
Oliver Gould
01d81b46c2 Add initial_connection_window_size to Builders (#249)
There is currently no way to configure the initial target window size
for connections. The `Builder::initial_connection_window_size` utilities
make this configurable so that all new connections have this target
window size set.
2018-03-28 14:46:56 -07:00
Carl Lerche
430d28723f Bump version to v0.1.3 (#248) 2018-03-28 12:50:46 -07:00
Eliza Weisman
23090c9fed recv_reset resets closed streams with queued EOS frames (#247) 2018-03-27 21:20:16 -07:00
Carl Lerche
e61788a57f Accept HPACK literals greater than max size (#244)
The spec specifically allows accepting HPACK literals with indexing when
the HPACK literal is greater than the max table size. In this case, the
literal is not inserted in the table.

Fixes #243
2018-03-22 12:58:23 -07:00
Darren Tsung
4595b54cfa Add initial_max_send_streams() as builder option (#242) 2018-03-16 11:58:06 -07:00
Carl Lerche
0cb3e648e9 Bump version to v0.1.2 (#239) 2018-03-13 18:11:11 -07:00
Carl Lerche
5d4c89b1a9 Fix client doc test (#241)
The test is not supposed to actually run, but the `select` is not fast
enough on Travis.
2018-03-13 14:53:35 -07:00
Darren Tsung
f8baeb7211 Streams receiving peer reset clear pending send (#238)
Because streams that were being peer reset were not clearing pending
send frames / buffered_send_data, they were not being counted towards
the concurrency limit.
2018-03-13 12:47:57 -07:00
messense
267789da92 Update indexmap to 1.0 (#237) 2018-03-12 10:38:07 -07:00
Carl Lerche
70cf009305 Bump version to v0.1.1 (#236) 2018-03-08 10:06:40 -08:00
Carl Lerche
02841ebd77 Normalize HTTP request path. (#228)
The HTTP/2.0 specification requires that the path pseudo header is never
empty for requests unless the request uses the OPTIONS method.

This is currently not correctly enforced.

This patch provides a test and a fix.
2018-03-07 20:48:54 -08:00
Darren Tsung
bbed41974b Prevent pushing a stream into both pending_send + pending_open (#235)
Prevent pushing a stream into both pending_send + pending_open,
Clear out variables from buffered streams that get a reset, and
ignore them when traversing the pending_send queue if
they are is_reset(). Add asserts that a stream cannot be in
pending_open & pending_send at the same time.
2018-03-07 16:11:33 -08:00
Darren Tsung
200c04f1d3 Fix tests by switching to env_logger::try_init (#233) 2018-03-07 14:08:22 -08:00
Carl Lerche
dd0bb5b03e Add a comment explaining what pending_open is for (#232)
It isn't immediately obvious why the connection supports buffering
requests. The reason is that it models the futures' mpsc channel
behavior.

This patch adds a comment explaining this.
2018-03-07 13:48:20 -08:00
Sean McArthur
e3c6e0c590 Notify send_tasks when there is a connection error (#231) 2018-03-07 12:19:54 -08:00
Darren Tsung
ad90f9b97b Remove assert around self.pending_capacity.is_empty() (#225)
This assert does not hold as many streams can be pushed into
pending_capacity during a call to send_data(). See issue #224
for more discussion and sign-off.

Closes #224
2018-02-27 10:35:00 -08:00
Brian Smith
06672cbde9 Upgrade ordermap dependency to indexmap. (#227)
Avoid the need for indexmap-based applications to build ordermap,
which is the old name for indexmap.

Signed-off-by: Brian Smith <brian@briansmith.org>
2018-02-26 20:27:13 -08:00
Brian Smith
b6724f7d7a Upgrade to env_logger 0.5 & log 0.4; reduce related dependencies (#226)
Upgrade to env_logger 0.5 and log 0.4 so that projects that use those
versions don't have to build both those versions and the older ones
that h2 is currently using.

Don't enable the regex support in env_logger. Applications that want
the regex support can enable it themselves; this will happen
automatically when they add their env_logger dependency.

Disable the env_logger dependency in quickcheck.

The result of this is that there are fewer dependencies. For example,
regex and its dependencies are no longer required at all, as can be
seen by observing the changes to the Cargo.lock. That said,
env_logger 0.5 does add more dependencies itself; however it seems
applications are going to use env_logger 0.5 anyway so this is still
a net gain.

Submitted on behalf of Buoyant, Inc.

Signed-off-by: Brian Smith <brian@briansmith.org>
2018-02-23 20:25:42 -08:00
Darren Tsung
0c59957d88 When Streams are dropped, close Connection (#221) (#222)
When all Streams are dropped / finished, the Connection was held
open until the peer hangs up. Instead, the Connection should hang up
once it knows that nothing more will be sent.

To fix this, we notify the Connection when a stream is no longer
referenced. On the Connection poll(), we check that there are no
active, held, reset streams or any references to the Streams
and transition to sending a GOAWAY if that is case.

The specific behavior depends on if running as a client or server.
2018-02-15 13:14:18 -08:00
walfie
73b4c03b55 Fix typos (#223) 2018-02-13 21:00:09 -08:00
Steven Fackler
ef99f99ae1 Fix documentation for end_of_stream (#219)
The END_STREAM flag is set when the stream is ending, so it needs to be
false if we're sending data.
2018-01-25 11:58:41 -08:00
Sean McArthur
ef6fef8714 update readme to point usage example at crates.io (#218) 2018-01-12 11:54:22 -08:00
Steven Fackler
9f4d463dba Update dependency spec (#217) 2018-01-12 11:48:10 -08:00
Carl Lerche
758112acbe Update README 2018-01-12 09:18:39 -08:00
Carl Lerche
69bd8828ef Remove mock-io git dependency 2018-01-11 22:46:52 -08:00
Carl Lerche
f27056467c Track rustls / ring 2018-01-11 22:35:47 -08:00
Carl Lerche
983477ea50 Depend on string 0.1 2018-01-11 22:21:19 -08:00
Carl Lerche
54f300907f Update the Cargo.toml 2018-01-11 21:21:53 -08:00
Carl Lerche
1c8abf50df Update the README 2018-01-11 21:15:15 -08:00
Carl Lerche
91e200a3b1 Cleanup repo 2018-01-11 21:00:59 -08:00
Carl Lerche
78455a4496 Add docs for shared types (#216)
Add documentation for types shared between the client and server.
2018-01-11 15:00:16 -08:00
Carl Lerche
5604372a8b Client documentation (#212)
Add documentation for client APIs.
2018-01-11 13:55:51 -08:00
Carl Lerche
1db3f34de8 Implement SendRequest::ready. (#215)
This provides a functional future API for waiting for SendRequest
readiness.
2018-01-11 10:21:23 -08:00
Sean McArthur
aa23a9735d SETTINGS_MAX_HEADER_LIST_SIZE (#206)
This, uh, grew into something far bigger than expected, but it turns out, all of it was needed to eventually support this correctly.

- Adds configuration to client and server to set [SETTINGS_MAX_HEADER_LIST_SIZE](http://httpwg.org/specs/rfc7540.html#SETTINGS_MAX_HEADER_LIST_SIZE)
- If not set, a "sane default" of 16 MB is used (taken from golang's http2)
- Decoding header blocks now happens as they are received, instead of buffering up possibly forever until the last continuation frame is parsed.
- As each field is decoded, it's undecoded size is added to the total. Whenever a header block goes over the maximum size, the `frame` will be marked as such.
- Whenever a header block is deemed over max limit, decoding will still continue, but new fields will not be appended to `HeaderMap`. This is also can save wasted hashing.
- To protect against enormous string literals, such that they span multiple continuation frames, a check is made that the combined encoded bytes is less than the max allowed size. While technically not exactly what the spec suggests (counting decoded size instead), this should hopefully only happen when someone is indeed malicious. If found, a `GOAWAY` of `COMPRESSION_ERROR` is sent, and the connection shut down.
- After an oversize header block frame is finished decoding, the streams state machine will notice it is oversize, and handle that.
  - If the local peer is a server, a 431 response is sent, as suggested by the spec.
  - A `REFUSED_STREAM` reset is sent, since we cannot actually give the stream to the user.
- In order to be able to send both the 431 headers frame, and a reset frame afterwards, the scheduled `Canceled` machinery was made more general to a `Scheduled(Reason)` state instead.

Closes #18 
Closes #191
2018-01-05 09:23:48 -08:00