mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-10 02:17:59 +00:00
use global semaphore in push_to_actor to prevent overloading system with outbound connections
This commit is contained in:
parent
f34b42ae78
commit
94e669cf7d
|
@ -30,6 +30,7 @@ if "actorKeys" not in DATABASE:
|
|||
PRIVKEY = RSA.importKey(DATABASE["actorKeys"]["privateKey"])
|
||||
PUBKEY = PRIVKEY.publickey()
|
||||
|
||||
sem = asyncio.Semaphore(500)
|
||||
|
||||
from . import app, CONFIG
|
||||
from .remote_actor import fetch_actor
|
||||
|
@ -77,7 +78,6 @@ get_actor_inbox = lambda actor: actor.get('endpoints', {}).get('sharedInbox', ac
|
|||
|
||||
async def push_message_to_actor(actor, message, our_key_id):
|
||||
inbox = get_actor_inbox(actor)
|
||||
|
||||
url = urlsplit(inbox)
|
||||
|
||||
# XXX: Digest
|
||||
|
@ -93,6 +93,8 @@ async def push_message_to_actor(actor, message, our_key_id):
|
|||
|
||||
logging.debug('%r >> %r', inbox, message)
|
||||
|
||||
global sem
|
||||
async with sem:
|
||||
try:
|
||||
async with aiohttp.ClientSession(trace_configs=[http_debug()]) as session:
|
||||
async with session.post(inbox, data=data, headers=headers) as resp:
|
||||
|
@ -308,5 +310,4 @@ async def inbox(request):
|
|||
|
||||
return aiohttp.web.Response(body=b'{}', content_type='application/activity+json')
|
||||
|
||||
|
||||
app.router.add_post('/inbox', inbox)
|
||||
|
|
Loading…
Reference in a new issue