Commit Graph

196 Commits

Author SHA1 Message Date
Michael Beaumont
586106adf2 Fix push promise frame parsing (#309) 2018-09-17 14:55:37 -07:00
Eliza Weisman
2b960b897d Add Reset::INTERNAL_ERROR helper to test support (#308)
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2018-09-13 16:33:44 -07:00
Sean McArthur
12028cc418 fix panic when calling reserve_capacity after connection closes (#302) 2018-08-08 15:43:47 -07:00
Geoffry Song
d2aa9197f9 Fix the handling of incoming SETTINGS_INITIAL_WINDOW_SIZE. (#299) 2018-08-03 16:00:13 -07:00
Sean McArthur
c564273986 fix graceful shutdown to close once idle (#296) 2018-07-30 21:42:00 -07:00
Geoffry Song
fdfb873438 Prevent pending_open streams from being released. (#295)
* Prevent `pending_open` streams from being released.

This fixes a panic that would otherwise occur in some cases. A test
demonstrating said panic is included.

* Clear the pending_open queue together with everything else.
2018-07-23 15:41:54 -07:00
Carl Lerche
df69c0455a Fix spurrious test failure (#288)
There was a race condition in the test where the server connection
sometimes closed before the final client opereation. This triggered an
unwrap in the test.

This patch updates the test to ensuree that the mock server connection
stays open until the client test is complete.
2018-06-18 11:20:18 -07:00
Arvid E. Picciani
74a5e072fe Fix tight loop on aborted connection (#285)
When the underlying IO returns 0 on read, we must stop polling it since
it's closed. Otherwise we'll be stuck in a tight loop.

this fixes https://github.com/sfackler/rust-openssl/issues/949
2018-06-15 16:04:13 -07:00
Geoffry Song
23234fa14f Promote SendRequest::pending to an OpaqueStreamRef. (#281)
Because `self.pending` doesn't necessarily get cleaned up in a timely fashion -
rather, only when the user calls `poll_ready()` - it was possible for it to
refer to a stream that has already been closed. This would lead to a panic the
next time that `poll_ready()` was called.

Instead, use an `OpaqueStreamRef`, bumping the refcount.

A change to an existing test is included which demonstrates the issue.
2018-06-06 10:16:22 -07:00
Sean McArthur
3a4633d205 add SendResponse::poll_reset and SendStream::poll_reset to listen for reset streams (#279) 2018-05-30 22:57:43 +02:00
johnklai1
6e63d7bae2 Wakeup waiting tasks when transitioning a stream from pending_open (#277) 2018-05-22 15:42:41 -07:00
Carl Lerche
bb454e017c Enforce monotonic stream IDs for push promises (#275)
Previously, monotonic stream IDs (spec 5.1.1) for push promises were not
enforced. This was due to push promises going through an entirely
separate code path than normally initiated streams.

This patch unifies the code path for initializing streams via both
HEADERS and PUSH_PROMISE. This is done by first calling `recv.open` in
both cases.

Closes #272
2018-05-14 10:20:57 -07:00
Carl Lerche
173f9a67e7 Include fuzz testing setup (#274) 2018-05-10 14:48:02 -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
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
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
Sean McArthur
dca336f8b2 send proper max stream ID in graceful goaway (#254) 2018-04-06 15:51:34 -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
Eliza Weisman
23090c9fed recv_reset resets closed streams with queued EOS frames (#247) 2018-03-27 21:20:16 -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
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
200c04f1d3 Fix tests by switching to env_logger::try_init (#233) 2018-03-07 14:08:22 -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
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
Carl Lerche
69bd8828ef Remove mock-io git dependency 2018-01-11 22:46:52 -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
Sean McArthur
6f7b826b0a fix name change in server tests (#213) 2018-01-04 11:45:08 -08:00
Sean McArthur
3cbc158210 send reset CANCEL when SendStream is dropped with no end-of-stream sent (#210) 2018-01-04 11:06:06 -08:00
Carl Lerche
d0b5b6246a Misc renames (#202)
This patch renames a number of types and functions making
the API more consistent.

* `Server` -> `Connection`
* `Client` -> `SendRequest`
* `Respond` -> `SendResponse`.

It also moves the handshake fns off of `Connection` and make
them free fns in the module. And `Connection::builder` is removed
in favor of `Builder::new`.
2018-01-02 17:02:17 -08:00
Sean McArthur
26e7a2d416 remove erroneous assert when stream has buffered send data (#209) 2018-01-02 12:49:41 -08:00
Carl Lerche
fc75311fae Support writing continuation frames. (#198)
Large header sets might require being split up across multiple frames.
This patch adds support for doing so.
2017-12-20 17:24:29 -08:00
Sean McArthur
a89401dd91 reset pending push promises if user drops all refs (#199) 2017-12-20 16:50:20 -08:00
Sean McArthur
10d8ed7429 Add test that a window update can be received in reserved state (#195) 2017-12-19 20:07:39 -08:00
Sean McArthur
1552d62e7c ignore trailers for some time on locally reset streams (#194) 2017-12-19 15:06:05 -08:00
Sean McArthur
eafd6bfd98 release connection capacity when recv_data has stream error (#186) 2017-12-18 15:08:21 -08:00
Sean McArthur
1ea9a8fc7e ignore received frames on a stream locally reset for some time (#174)
- Adds config duration for how long to ignore frames on a reset stream
- Adds config for how many reset streams can be held at a time
2017-12-18 11:09:38 -08:00
Carl Lerche
9378846da8 Client should validate request URI. (#181)
This patch adds checks for the request URI and rejects invalid URIs. In
the case of forwarding an HTTP 1.1 request with a path, an "http" pseudo
header is added to satisfy the HTTP/2.0 spec.

Closes #179
2017-12-11 13:42:00 -06:00
Sean McArthur
6c68f72fbd notify stream send task when receiving EOF (#178)
* notify stream send task when receiving EOF

* record a conn_error on eof so client can see it

* fix stream id overflow test
2017-12-01 15:58:04 -08:00
Carl Lerche
5d54d8cd79 Fix flow control bug (#177)
This patch fixes a bug that prevents sent data from being flushed to the
socket.

When data is sent, the task managing the connection must be notified. A
guard exists that prevents unnecessary notification of the connection
when the stream does not have any send capacity. However, this guard was
buggy. Instead of notifying the connection if *any* data can be sent, it
notified the connection only when *all* data could be sent.

This patch fixes the check as well as adds some tests that ensure the
connection task is notified.
2017-11-29 12:54:23 -08:00
Sean McArthur
2be2523162 notify stream refs when the connection receives EOF (#176) 2017-11-28 13:42:22 -08:00
Sean McArthur
79003d0d45 reject connection-specific headers (#173)
- When receiving, return a PROTOCOL_ERROR.
- When sending, return a user error about malformed headers.

Closes #36
2017-11-14 11:16:29 -08:00
Eliza Weisman
05abb686cf Add test for #38 (#162)
As requested in https://github.com/carllerche/h2/issues/38#issuecomment-328254128, I've added a test to `stream_states.rs` to cover the case where we receive a HEADERS frame that gets rejected (due to being malformed), then the same stream ID is received with a valid HEADERS frame which gets accepted.

Closes #38
2017-10-27 15:22:12 -07:00
Eliza Weisman
8a1c4d3d52 Add test and assertion for idle state handling (#160) 2017-10-27 14:14:00 -07:00
Carl Lerche
c23d11306e Add RecvStream::is_end_stream. (#165)
This function returns true if the `RecvStream` has reached an end of
stream state. This is intended to replace `is_empty` which has confusing
behavior.
2017-10-21 09:59:27 -07:00