Skip to content

Commit ebda9ae

Browse files
authored
Merge pull request #42 from icgood/ref
Keep a reference to the connect task
2 parents a3de80a + c2e6681 commit ebda9ae

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

proxyprotocol/server/protocol.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ def proxy_data(self, data: bytes) -> None:
107107

108108
class DownstreamProtocol(_Base):
109109

110-
__slots__ = ['loop', 'dnsbl', 'upstream', 'id', '_dnsbl_task', '_waiting',
111-
'_waiting_closed', '_upstream', '_upstream_factory']
110+
__slots__ = ['loop', 'dnsbl', 'upstream', 'id', '_waiting',
111+
'_waiting_closed', '_upstream', '_upstream_factory',
112+
'_dnsbl_task', '_connect_task']
112113

113114
def __init__(self, upstream_protocol: Type[UpstreamProtocol],
114115
loop: AbstractEventLoop, buf_len: int, dnsbl: Dnsbl,
@@ -119,6 +120,7 @@ def __init__(self, upstream_protocol: Type[UpstreamProtocol],
119120
self.upstream: Final = upstream
120121
self.id: Final = uuid4().bytes
121122
self._dnsbl_task: Optional[Task[Optional[str]]] = None
123+
self._connect_task: Optional[Task[_Connect]] = None
122124
self._waiting: Deque[bytes] = deque()
123125
self._waiting_closed = False
124126
self._upstream: Optional[UpstreamProtocol] = None
@@ -128,6 +130,8 @@ def __init__(self, upstream_protocol: Type[UpstreamProtocol],
128130
def _set_client(self, result: ProxyResult,
129131
connect_task: Task[_Connect]) -> None:
130132
dnsbl_task = self._dnsbl_task
133+
self._dnsbl_task = None
134+
self._connect_task = None
131135
assert dnsbl_task is not None
132136
try:
133137
_, upstream = connect_task.result()
@@ -157,7 +161,7 @@ def connection_made(self, transport: BaseTransport) -> None:
157161
self.id.hex(), self.sock_info)
158162
loop = self.loop
159163
self._dnsbl_task = loop.create_task(self.dnsbl.lookup(self.sock_info))
160-
connect_task = loop.create_task(
164+
self._connect_task = connect_task = loop.create_task(
161165
loop.create_connection(self._upstream_factory,
162166
self.upstream.host, self.upstream.port or 0,
163167
ssl=self.upstream.ssl))

proxyprotocol/version.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from __future__ import annotations
33

44
from enum import Enum
5-
from typing import cast, Optional
5+
from typing import Optional
66

77
from . import ProxyProtocol
88
from .detect import ProxyProtocolDetect
@@ -44,4 +44,6 @@ def get(cls, name: Optional[str] = None) -> ProxyProtocol:
4444
"""
4545
if not name:
4646
return cls.NOOP.value
47-
return cast(ProxyProtocol, cls[name.upper()].value)
47+
pp = cls[name.upper()].value
48+
assert isinstance(pp, ProxyProtocol)
49+
return pp

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2021 Ian C. Good
1+
# Copyright (c) 2023 Ian C. Good
22
#
33
# Permission is hereby granted, free of charge, to any person obtaining a copy
44
# of this software and associated documentation files (the "Software"), to deal
@@ -28,7 +28,7 @@
2828
license = f.read()
2929

3030
setup(name='proxy-protocol',
31-
version='0.9.0',
31+
version='0.9.1',
3232
author='Ian Good',
3333
author_email='ian@icgood.net',
3434
description='PROXY protocol library with asyncio server implementation',

0 commit comments

Comments
 (0)