clj-commons / clj-commons/aleph

Potential connections leak when response body is not consumed

Open
#402 3 comments 0 reactions 0 assignees View on GitHub
operational improvements
Dominant language
Clojure
Stars
2.6k
Forks
242
Avg merge
4d 5h
Merged PRs (30d)
1

Description

It's not an Aleph issue specifically... more like a flaw of async event-driven HTTP communication. Unfortunately with practical implications.

Let's assume I'm using HTTP client and

1. The server responds with the body that exceeds `:response-buffer-size`

2. I do not use `:body` of the response at all (e.g. I just read headers) or failed to read the entire body.

By default `read-timeout` is not set, so the client will wait until the body consumption is complete "always" (unless server closes the connection, but we cannot rely on that fact at all). Effectively blocking an acquired connection from the pool. Which eventually would lead to the pool being exhausted and application being "stuck".

In the ideal world, we need to ensure that after response processing is done at least on the requirements is met: either `:body` is fully consumed or underlying connection is closed. As we cannot do the first, I think it makes sense at least to introduce an API to have an option to close connection explicitly manually.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the HTTP client response-body consumption and connection-pool lifecycle, then reproduce the case with a response larger than :response-buffer-size whose body is not fully read. Done should provide a documented way to close the underlying connection explicitly and prevent an unconsumed response from exhausting the pool.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
api, backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.