Commit Graph

300 Commits

Author SHA1 Message Date
Oliver Gould
4dc2b4a164 Avoid time operations that can panic
We have reports of runtime panics (linkerd/linkerd2#7748) that sound a
lot like rust-lang/rust#86470. We don't have any evidence that these
panics originate in h2, but there is one use of `Instant::sub` that
could panic in this way.

Even though this is almost definitely a bug in Rust, it seems most
prudent to actively avoid the uses of `Instant` that are prone to this
bug. These fixes should ultimately be made in the standard library, but
this change lets us avoid this problem while we wait for those fixes.

This change replaces uses of `Instant::elapsed` and `Instant::sub` with
calls to `Instant::saturating_duration_since` to prevent this class of
panic.

See also hyperium/hyper#2746
2022-01-31 16:22:32 -08:00
Sean McArthur
7de2ccc1a3 fix panic when receiving already reset push promise (#597)
Found by oss-fuzz
2022-01-21 15:41:39 -08:00
Anthony Ramine
d92ba1c45b Make SendStream::poll_capacity never return Ok(Some(0)) (#596)
Fixes #270
2022-01-19 10:49:53 -08:00
Sean McArthur
a5c60b24de Fix poll_capacity to wake in combination with max_send_buffer_size 2021-12-09 09:20:01 -08:00
Sean McArthur
efa113bac6 Add max send buffer per stream option (#580) 2021-12-08 10:03:15 -08:00
Anthony Ramine
87969c1f29 Implement the extended CONNECT protocol from RFC 8441 (#565) 2021-11-24 10:05:10 +01:00
Sean McArthur
405972739b Fix panic if remote causes local to reset a stream before opening 2021-10-22 09:47:30 -07:00
Anthony Ramine
f52d5e6290 Replace HTTP/2.0 by HTTP/2 😅
The protocol is named HTTP/2.
2021-10-20 11:10:25 -07:00
Anthony Ramine
508bcb1d27 Store buffered data size as usize (fixes #269) (#542) 2021-09-28 09:05:06 -07:00
Anthony Ramine
465f0337f8 Refactor errors internals (#556)
h2::Error now knows whether protocol errors happened because the user
sent them, because it was received from the remote peer, or because
the library itself emitted an error because it detected a protocol
violation.

It also keeps track of whether it came from a RST_STREAM or GO_AWAY
frame, and in the case of the latter, it includes the additional
debug data if any.

Fixes #530
2021-09-28 09:04:35 -07:00
Anthony Ramine
96d9277454 Remove code that was made obsolete by #555 2021-09-13 12:19:11 -07:00
Anthony Ramine
61b4f8fc34 Support very large headers
This completely refactors how headers are hpack-encoded.

Instead of trying to be clever, constructing frames on the go
while hpack-encoding, we just make a blob of all the
hpack-encoded headers first, and then we split that blob
in as many frames as necessary.
2021-09-08 10:20:30 -07:00
Sean McArthur
ab6f148ee1 Fix potential hang if extensions contain same StreamRef
If a user stored a `StreamRef` to the same stream in the request or
response extensions, they would be dropped while the internal store lock
was held. That would lead to a deadlock, since dropping a stream ref
will try to take the store lock to clean up.

Clear extensions of Request and Response before locking store, prevent
this.

Fixes hyperium/hyper#2621
2021-08-20 14:44:08 -07:00
Anthony Ramine
47d107aa17 Wake up connection when dropping SendRequest (#538)
Fixes #502
2021-05-06 11:57:44 -07:00
boxdot
04570652b7 Do not use Instant::now when zero reset streams are configured. (#537)
This allows to use `h2` on wasm platforms which lack an
`Instant::now` implementation by setting the number of streams to
0 with: `h2::client::Builder::max_concurrent_reset_streams`.
2021-05-05 09:28:45 -07:00
Anthony Ramine
c3bc09550e Remove commented-out code 2021-04-29 09:18:12 -07:00
Anthony Ramine
a1f914f46f Skip 1xx frames in more states (#527)
#524

Co-authored-by: Kornel <kornel@cloudflare.com>
2021-03-24 08:03:12 -07:00
Josh Soref
bcaaaf6dd9 Spelling fixes in comments (#508) 2021-02-25 08:59:18 -08:00
Eliza Weisman
c1b411fc14 add Connection::max_concurrent_recv_streams (#516)
This commit adds accessors to `client::Connection` and
`server::Connection` that return the current value of the
`SETTINGS_MAX_CONCURRENT_STREAMS` limit that has been sent by this peer
and acknowledged by the remote.

This is analogous to the `max_concurrent_send_streams` methods added in
PR #513. These accessors may be somewhat less useful than the ones for
the values negotiated by the remote, since users who care about this
limit are probably setting the builder parameter. However, it seems
worth having for completeness sake --- and it might be useful for
determining whether or not a configured concurrency limit has been acked
yet...

Part of #512
2021-02-25 08:58:19 -08:00
Kornel
89d91b0a4f Ignore 1xx frames (#521)
Closes #515
2021-02-25 08:57:42 -08:00
Markus Westerlind
30ca832790 Make some functions less-generic to reduce binary bloat (#503)
* refactor: Extract FramedWrite::buffer to a less generic function

Should cut out another 23 KiB (since I see it duplicated)

* refactor: Extract some duplicated code to a function

* refactor: Extract part of flush into a less generic function

* refactor: Extract a less generic part of connection

* refactor: Factor out a less generic part of Connection::poll2

* refactor: Extract a non-generic part of handshake2

* refactor: Don't duplicate Streams code on Peer (-3.5%)

The `P: Peer` parameter is rarely used and there is already a mechanism
for using it dynamically.

* refactor: Make recv_frame less generic (-2.3%)

* Move out part of Connection::poll

* refactor: Extract parts of Connection

* refactor: Extract a non-generic part of reclaim_frame

* comments
2021-02-18 11:17:49 -08:00
Eliza Weisman
978c71270a add Connection::max_concurrent_send_streams (#513)
This PR adds accessors to `client::Connection` and `server::Connection`
that return the send stream concurrency limit on that connection, as
negotiated by the remote peer. This is part of issue #512.

I think we probably ought to expose similar accessors for other
settings, but I thought it was better to add each one in a separate,
focused PR.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-02-05 09:58:10 -08:00
Eliza Weisman
2c8c847cd5 Replace deprecated compare_and_swap with compare_exchange (#514)
The `compare_and_swap` method on atomics is now deprecated in favor
of `compare_exchange`.

Since the author of #510 closed that PR, this is just #510 with rustfmt run.

I also removed an unnecessary trailing semicolon that the latest rust
compiler now complains about.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>

Co-authored-by: Kornel <kornel@cloudflare.com>
2021-02-05 09:27:27 -08:00
Sean McArthur
b4976675fa Update to Tokio and Bytes 1.0 (#504) 2020-12-23 10:01:44 -08:00
Paolo Barbolini
5a92f256c0 Upgrade to bytes 0.6 (#497)
* Upgrade to bytes 0.6

* Update Cargo.toml

Co-authored-by: Eliza Weisman <eliza@buoyant.io>

* Update tests/h2-support/Cargo.toml

Co-authored-by: Eliza Weisman <eliza@buoyant.io>

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2020-11-19 14:38:56 -08:00
Yuchen Wu
0ba7d13ae5 Allow responses of HEAD requests to have empty DATA frames (#490) 2020-10-22 14:36:41 -07:00
eggyal
2b19acf132 Handle client-disabled server push (#486) 2020-09-17 17:25:31 -07:00
Eliza Weisman
fc7f63f641 start adding tracing spans to internals (#478)
We've adopted `tracing` for diagnostics, but currently, it is just being
used as a drop-in replacement for the `log` crate. Ideally, we would
want to start emitting more structured diagnostics, using `tracing`'s
`Span`s and structured key-value fields.

A lot of the logging in `h2` is already written in a style that imitates
the formatting of structured key-value logs, but as textual log
messages. Migrating the logs to structured `tracing` events therefore is
pretty easy to do. I've also started adding spans, mostly in the read
path.

Finally, I've updated the tests to use `tracing` rather than
`env_logger`. The tracing setup happens in a macro, so that a span for
each test with the test's name can be generated and entered. This will
make the test output easier to read if multiple tests are run
concurrently with `--nocapture`.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-08-17 17:29:22 -07:00
Michael Beaumont
d3c2bba18b Increment Stream.refs when sending a push promise 2020-08-17 15:54:47 -07:00
Michael Beaumont
6d80bd454e Fix handling Streams.refs in next_incoming
`Streams.inner.ref` doesn't need to be incremented if we don't
return an `OpaqueStreamRef`.

This prevented the bug in `send_push_promise` from appearing
in the tests.
2020-08-17 15:54:47 -07:00
David Barsky
d3b9f1e36a feat(lib): switch from log to tracing (#475) 2020-07-07 15:55:24 -07:00
Sean McArthur
c460c6e581 Change store debug_assert to only run in tests 2020-05-06 12:55:19 -07:00
Sean McArthur
e41a1f130c Respect SETTINGS_HEADER_TABLE_SIZE (#459) 2020-03-30 11:53:22 -07:00
Sean McArthur
d6dc63276f Fix receiving a GOAWAY frame from updating the max recv ID
Receiving a GOAWAY should update the max *send* ID, it shouldn't affect
the max recv.
2020-03-25 10:08:13 -07:00
Sean McArthur
1b01300eeb Use a u32 index for stream store (#451)
A connection can never have more than u32::MAX >> 1 streams, so we'll
never store more than that many in the store slab. Define the
`SlabIndex` as a `u32` to reduce the number of bytes moved around.
2020-02-28 15:30:48 -08:00
Sean McArthur
ec751f3696 Remove Unpin requirement for the send Buf 2019-12-06 11:40:08 -08:00
Sean McArthur
4398e169e8 Update to Tokio 0.2 (#428) 2019-11-27 14:53:57 -08:00
Sean McArthur
86e53054a6 Change ReserveCapacity to expanded FlowControl type (#423)
- Adds `FlowControl::available_capacity` method.
- Adds `FlowControl::used_capacity` method.
2019-10-08 11:28:15 -07:00
Sean McArthur
4c1d797712 Add ability to adjust INITIAL_WINDOW_SIZE setting on an existing connection (#421) 2019-10-07 15:29:23 -07:00
Michael Beaumont
fac165e451 Add server support for push (#327)
Closes #291, closes #185
2019-09-16 11:30:58 -07:00
Michael Beaumont
06a68a76a2 Use IndexMap::swap_remove instead of deprecated IndexMap::remove 2019-09-12 12:22:17 -07:00
Sean McArthur
2d90efee17 Prune futures-* dependencies 2019-08-30 14:53:49 -07:00
Sean McArthur
f31ec5d0da Remove deprecated-in-0.1.x APIs 2019-08-20 15:15:04 -07:00
Gurwinder Singh
f46840f3fa chore: cargo fmt, clippy 2019-08-16 22:27:39 -07:00
Gurwinder Singh
ad7ffa795f Updated as per review comments 2019-08-16 18:47:47 -07:00
Gurwinder Singh
c8fefd49f1 Update lib to std-future 2019-08-16 18:47:47 -07:00
Jakub Beránek
db6b841e67 Update crate to Rust 2018 (#383) 2019-07-23 10:18:43 -07:00
Sean McArthur
ab52cf9b30 Send RST_STREAM of STREAM_CLOSED instead of GOAWAY if stream may have been forgotten 2019-06-28 12:48:42 -07:00
Sean McArthur
f8f05d04e7 Fix trailers without EOS flag to be a stream instead of connection error (#377)
[Trailers without EOS](https://httpwg.org/specs/rfc7540.html#HttpSequence):

> An endpoint that receives a HEADERS frame without the END_STREAM flag set after receiving a final (non-informational) status code MUST treat the corresponding request or response as malformed (Section 8.1.2.6).

[Malformed messages](https://httpwg.org/specs/rfc7540.html#malformed):

> Malformed requests or responses that are detected MUST be treated as a stream error (Section 5.4.2) of type PROTOCOL_ERROR.
2019-06-26 13:38:06 -07:00
Eliza Weisman
0e9fbe4a90 Log protocol error causes at debug (#371)
Currently, there are many cases where `h2` will fail a connection or
stream with a PROTOCOL_ERROR, without recording why the protocol error
occurred. Since protocol errors may result from a bug in `h2` or from a
misbehaving peer, it is important to be able to debug the cause of
protocol errors.

This branch adds a log line to almost all cases where a protocol error
occurs. I've tried to make the new log lines consistent with the
existing logging, and in some cases, changed existing log lines to make
them internally consistent with other log lines in that module. All
receive-side errors that would send a reset are now logged at the debug
level, using a formatting based on the format used in `framed_read`.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-06-17 14:14:40 -07:00