Agent: Add a timeout on TCPPipeSpawner dest socket

This commit is contained in:
Mike Salvatore 2022-09-12 16:29:19 -04:00
parent 77c97062eb
commit 9002c47d56
3 changed files with 6 additions and 2 deletions

View File

@ -0,0 +1 @@
SOCKET_TIMEOUT = 10

View File

@ -5,8 +5,9 @@ from logging import getLogger
from threading import Thread
from typing import Callable
from .consts import SOCKET_TIMEOUT
READ_BUFFER_SIZE = 8192
SOCKET_READ_TIMEOUT = 10
logger = getLogger(__name__)
@ -19,7 +20,7 @@ class SocketsPipe(Thread):
source,
dest,
pipe_closed: Callable[[SocketsPipe], None],
timeout=SOCKET_READ_TIMEOUT,
timeout=SOCKET_TIMEOUT,
):
self.source = source
self.dest = dest

View File

@ -3,6 +3,7 @@ from ipaddress import IPv4Address
from threading import Lock
from typing import Set
from .consts import SOCKET_TIMEOUT
from .sockets_pipe import SocketsPipe
@ -25,6 +26,7 @@ class TCPPipeSpawner:
:raises OSError: If a socket to the configured client could not be created.
"""
dest = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dest.settimeout(SOCKET_TIMEOUT)
try:
dest.connect((str(self._target_addr), self._target_port))
except OSError as err: