Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish client stream after trailer headers #159

Merged
merged 1 commit into from
Feb 18, 2022

Conversation

quernd
Copy link
Contributor

@quernd quernd commented Feb 9, 2022

I noticed a memory leak which occurs in the following setting:

  • one long-running client connection
  • multiple streams that share this connection (sequentially or in parallel)
    The memory is only freed when the connection is closed.

It seems to come down to the client streams not being "finished" after receiving trailing headers.

I benchmarked with Memtrace and with this change, memory consumption is now stable.

Copy link
Owner

@anmonteiro anmonteiro left a comment

Choose a reason for hiding this comment

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

Very nice find. I'll fix the same bug in server_connection.ml. Thanks!

@anmonteiro anmonteiro merged commit 4106ad2 into anmonteiro:master Feb 18, 2022
@quernd quernd deleted the finish-client-stream branch February 18, 2022 07:07
anmonteiro added a commit that referenced this pull request Feb 18, 2022
anmonteiro added a commit that referenced this pull request Feb 18, 2022
* Finish server stream after trailer headers

* add changelog entry for #159 and #160
ansiwen pushed a commit to ansiwen/ocaml-h2 that referenced this pull request May 2, 2022
anmonteiro added a commit to anmonteiro/opam-repository that referenced this pull request Aug 15, 2022
…(0.9.0)

CHANGES:

- h2: Fix tests on 32-bit platforms
  ([anmonteiro/ocaml-h2#152](anmonteiro/ocaml-h2#152))
- h2-mirage: adapt to Conduit v4 and remove `H2_mirage.Server_with_conduit`
  ([anmonteiro/ocaml-h2#154](anmonteiro/ocaml-h2#154))
- h2: fix memory leaks related to trailer headers in the server and client
  implementations ([anmonteiro/ocaml-h2#159](anmonteiro/ocaml-h2#159)
  (thanks [@quernd](https://github.com/quernd)!),
  [anmonteiro/ocaml-h2#160](anmonteiro/ocaml-h2#160))
- h2: allow configuring `flush_headers_immediately` on the client and default
  to `false`. This means that h2 will wait for the first request body bytes to
  be scheduled and batch `HEADERS` and `DATA` frames when sending requests
  ([anmonteiro/ocaml-h2#163](anmonteiro/ocaml-h2#163),
  [anmonteiro/ocaml-h2#164](anmonteiro/ocaml-h2#164))
- h2: Split `Body.t` into `Body.Writer.t` and `Body.Reader.t`
  ([anmonteiro/ocaml-h2#165](anmonteiro/ocaml-h2#165))
- h2: OCaml 5.00 compatibility -- add `seeded_hash` to `scheduler.ml`
  ([anmonteiro/ocaml-h2#168](anmonteiro/ocaml-h2#168))
- h2: Use a tail-recursive version of `Angstrom.skip_many`. Fixes a memory leak
  in long-running connections e.g. gRPC
  ([anmonteiro/ocaml-h2#172](anmonteiro/ocaml-h2#172))
- h2-async: Add an OCaml-TLS client to `h2-async`
  ([anmonteiro/ocaml-h2#174](anmonteiro/ocaml-h2#174))
- h2: Fix a bug that caused different requests to share the same headers buffer
  under concurrency ([anmonteiro/ocaml-h2#182](anmonteiro/ocaml-h2#182))
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.

None yet

2 participants