Skip to content

Commit

Permalink
Ensure no socket leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavsingh committed Oct 16, 2019
1 parent 0ac69b3 commit d4fe97f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,11 +1101,13 @@ def run_once(self) -> None:
def run(self) -> None:
self.running = True
self.selector = selectors.DefaultSelector()
fileno = recv_handle(self.work_queue)
self.sock = socket.fromfd(
recv_handle(self.work_queue),
fileno,
family=self.family,
type=socket.SOCK_STREAM
)
os.close(fileno)
try:
self.selector.register(self.sock, selectors.EVENT_READ)
self.start_threadless_process()
Expand Down Expand Up @@ -2507,9 +2509,11 @@ def shutdown(self) -> None:
logger.debug('Client connection closed')

def fromfd(self, fileno: int) -> socket.socket:
return socket.fromfd(
conn = socket.fromfd(
fileno, family=socket.AF_INET if self.config.hostname.version == 4 else socket.AF_INET6,
type=socket.SOCK_STREAM)
os.close(fileno)
return conn

def optionally_wrap_socket(
self, conn: socket.socket) -> Union[ssl.SSLSocket, socket.socket]:
Expand Down

0 comments on commit d4fe97f

Please sign in to comment.