-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTTP: radically simplify pool checkin/checkout
Use a custom tesla middleware instead of adapter helper function + custom redirect middleware. This will also fix "Client died before releasing the connection" messages when the request pool is overloaded. Since the checkout is now done after passing ConcurrentLimiter. This is technically less efficient, since the connection needs to be checked in/out every time the middleware is left or entered respectively. But I don't think the nanoseconds we might lose on redirects to the same host are worth the complexity.
- Loading branch information
rinpatch
committed
Sep 3, 2020
1 parent
9433311
commit d34fe28
Showing
6 changed files
with
51 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Pleroma: A lightweight social networking server | ||
# Copyright © 2020 Pleroma Authors <https://pleroma.social/> | ||
# SPDX-License-Identifier: AGPL-3.0-only | ||
|
||
defmodule Pleroma.Tesla.Middleware.ConnectionPool do | ||
@moduledoc """ | ||
Middleware to get/release connections from `Pleroma.Gun.ConnectionPool` | ||
""" | ||
|
||
@behaviour Tesla.Middleware | ||
|
||
alias Pleroma.Gun.ConnectionPool | ||
|
||
@impl Tesla.Middleware | ||
def call(%Tesla.Env{url: url, opts: opts} = env, next, _) do | ||
uri = URI.parse(url) | ||
|
||
case ConnectionPool.get_conn(uri, opts[:adapter]) do | ||
{:ok, conn_pid} -> | ||
adapter_opts = Keyword.merge(opts[:adapter], conn: conn_pid, close_conn: false) | ||
opts = Keyword.put(opts, :adapter, adapter_opts) | ||
env = %{env | opts: opts} | ||
res = Tesla.run(env, next) | ||
|
||
unless opts[:adapter][:body_as] == :chunks do | ||
ConnectionPool.release_conn(conn_pid) | ||
end | ||
|
||
res | ||
|
||
err -> | ||
err | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.