1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-02-03 13:47:14 +03:00

fixed udstunnel connection stop event bein the same for all connections

This commit is contained in:
Adolfo Gómez García 2022-12-20 23:39:51 +01:00
parent d707771fe5
commit c1e4c5b81a
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
2 changed files with 5 additions and 7 deletions

View File

@ -51,6 +51,7 @@ class Proxy:
def __init__(self, cfg: 'config.ConfigurationType', ns: 'Namespace') -> None:
self.cfg = cfg
self.ns = ns
self.finished = asyncio.Event()
# Method responsible of proxying requests
async def __call__(self, source: socket.socket, context: 'ssl.SSLContext') -> None:
@ -70,7 +71,6 @@ class Proxy:
loop = asyncio.get_running_loop()
# Handshake correct in this point, upgrade the connection to TSL and let
# the protocol controller do the rest
self.finished = asyncio.Event()
# Upgrade connection to SSL, and use asyncio to handle the rest
try:

View File

@ -130,9 +130,6 @@ async def tunnel_proc_async(
return None, None
async def run_server() -> None:
# Instantiate a proxy redirector for this process (we only need one per process!!)
tunneler = proxy.Proxy(cfg, ns)
# Generate SSL context
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
args: typing.Dict[str, typing.Any] = {
@ -159,7 +156,8 @@ async def tunnel_proc_async(
if not sock:
break # No more sockets, exit
logger.debug(f'CONNECTION from {address!r} (pid: {os.getpid()})')
tasks.append(asyncio.create_task(tunneler(sock, context)))
# Due to proxy contains an "event" to stop, we need to create a new one for each connection
tasks.append(asyncio.create_task(proxy.Proxy(cfg, ns)(sock, context)))
except asyncio.CancelledError:
raise
except Exception:
@ -172,8 +170,8 @@ async def tunnel_proc_async(
try:
while tasks and running.is_set():
to_wait = tasks[:] # Get a copy of the list, and clean the original
# Wait for tasks to finish, stop every 2 seconds to check if we need to finish
to_wait = tasks[:] # Get a copy of the list
# Wait for "to_wait" tasks to finish, stop every 2 seconds to check if we need to stop
done, _ = await asyncio.wait(to_wait, return_when=asyncio.FIRST_COMPLETED, timeout=2)
# Remove finished tasks
for task in done: