stompman 3.3.0__tar.gz → 3.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stompman-3.3.0 → stompman-3.5.0}/PKG-INFO +1 -1
- {stompman-3.3.0 → stompman-3.5.0}/stompman/connection.py +3 -5
- {stompman-3.3.0 → stompman-3.5.0}/stompman/connection_manager.py +31 -14
- {stompman-3.3.0 → stompman-3.5.0}/stompman/errors.py +2 -0
- {stompman-3.3.0 → stompman-3.5.0}/.gitignore +0 -0
- {stompman-3.3.0 → stompman-3.5.0}/pyproject.toml +0 -0
- {stompman-3.3.0 → stompman-3.5.0}/stompman/__init__.py +0 -0
- {stompman-3.3.0 → stompman-3.5.0}/stompman/client.py +0 -0
- {stompman-3.3.0 → stompman-3.5.0}/stompman/config.py +0 -0
- {stompman-3.3.0 → stompman-3.5.0}/stompman/connection_lifespan.py +0 -0
- {stompman-3.3.0 → stompman-3.5.0}/stompman/frames.py +0 -0
- {stompman-3.3.0 → stompman-3.5.0}/stompman/logger.py +0 -0
- {stompman-3.3.0 → stompman-3.5.0}/stompman/py.typed +0 -0
- {stompman-3.3.0 → stompman-3.5.0}/stompman/serde.py +0 -0
- {stompman-3.3.0 → stompman-3.5.0}/stompman/subscription.py +0 -0
- {stompman-3.3.0 → stompman-3.5.0}/stompman/transaction.py +0 -0
|
@@ -37,7 +37,7 @@ def _reraise_connection_lost(*causes: type[Exception]) -> Generator[None, None,
|
|
|
37
37
|
try:
|
|
38
38
|
yield
|
|
39
39
|
except causes as exception:
|
|
40
|
-
raise ConnectionLostError from exception
|
|
40
|
+
raise ConnectionLostError(reason=exception) from exception
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
@dataclass(kw_only=True, slots=True)
|
|
@@ -85,10 +85,8 @@ class Connection(AbstractConnection):
|
|
|
85
85
|
await self.writer.drain()
|
|
86
86
|
|
|
87
87
|
async def _read_non_empty_bytes(self, max_chunk_size: int) -> bytes:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
) == b"": # pragma: no cover (it definitely happens)
|
|
91
|
-
await asyncio.sleep(0)
|
|
88
|
+
if (chunk := await self.reader.read(max_chunk_size)) == b"":
|
|
89
|
+
raise ConnectionLostError(reason="eof")
|
|
92
90
|
return chunk
|
|
93
91
|
|
|
94
92
|
async def read_frames(self) -> AsyncGenerator[AnyServerFrame, None]:
|
|
@@ -55,10 +55,12 @@ class ConnectionManager:
|
|
|
55
55
|
_reconnect_lock: asyncio.Lock = field(init=False, default_factory=asyncio.Lock)
|
|
56
56
|
_task_group: asyncio.TaskGroup = field(init=False, default_factory=asyncio.TaskGroup)
|
|
57
57
|
_send_heartbeat_task: asyncio.Task[None] = field(init=False, repr=False)
|
|
58
|
+
_check_server_heartbeat_task: asyncio.Task[None] = field(init=False, repr=False)
|
|
58
59
|
|
|
59
60
|
async def __aenter__(self) -> Self:
|
|
60
61
|
await self._task_group.__aenter__()
|
|
61
62
|
self._send_heartbeat_task = self._task_group.create_task(asyncio.sleep(0))
|
|
63
|
+
self._check_server_heartbeat_task = self._task_group.create_task(asyncio.sleep(0))
|
|
62
64
|
self._active_connection_state = await self._get_active_connection_state(is_initial_call=True)
|
|
63
65
|
return self
|
|
64
66
|
|
|
@@ -66,7 +68,8 @@ class ConnectionManager:
|
|
|
66
68
|
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
|
|
67
69
|
) -> None:
|
|
68
70
|
self._send_heartbeat_task.cancel()
|
|
69
|
-
|
|
71
|
+
self._check_server_heartbeat_task.cancel()
|
|
72
|
+
await asyncio.wait([self._send_heartbeat_task, self._check_server_heartbeat_task])
|
|
70
73
|
await self._task_group.__aexit__(exc_type, exc_value, traceback)
|
|
71
74
|
|
|
72
75
|
if not self._active_connection_state:
|
|
@@ -77,11 +80,15 @@ class ConnectionManager:
|
|
|
77
80
|
return
|
|
78
81
|
await self._active_connection_state.connection.close()
|
|
79
82
|
|
|
80
|
-
def
|
|
83
|
+
def _restart_heartbeat_tasks(self, server_heartbeat: Heartbeat) -> None:
|
|
81
84
|
self._send_heartbeat_task.cancel()
|
|
85
|
+
self._check_server_heartbeat_task.cancel()
|
|
82
86
|
self._send_heartbeat_task = self._task_group.create_task(
|
|
83
87
|
self._send_heartbeats_forever(server_heartbeat.want_to_receive_interval_ms)
|
|
84
88
|
)
|
|
89
|
+
self._check_server_heartbeat_task = self._task_group.create_task(
|
|
90
|
+
self._check_server_heartbeat_forever(server_heartbeat.will_send_interval_ms)
|
|
91
|
+
)
|
|
85
92
|
|
|
86
93
|
async def _send_heartbeats_forever(self, send_heartbeat_interval_ms: int) -> None:
|
|
87
94
|
send_heartbeat_interval_seconds = send_heartbeat_interval_ms / 1000
|
|
@@ -89,6 +96,15 @@ class ConnectionManager:
|
|
|
89
96
|
await self.write_heartbeat_reconnecting()
|
|
90
97
|
await asyncio.sleep(send_heartbeat_interval_seconds)
|
|
91
98
|
|
|
99
|
+
async def _check_server_heartbeat_forever(self, receive_heartbeat_interval_ms: int) -> None:
|
|
100
|
+
receive_heartbeat_interval_seconds = receive_heartbeat_interval_ms / 1000
|
|
101
|
+
while True:
|
|
102
|
+
await asyncio.sleep(receive_heartbeat_interval_seconds * self.check_server_alive_interval_factor)
|
|
103
|
+
if not self._active_connection_state:
|
|
104
|
+
continue
|
|
105
|
+
if not self._active_connection_state.is_alive(self.check_server_alive_interval_factor):
|
|
106
|
+
self._clear_active_connection_state(ConnectionLostError(reason="server heartbeat timeout"))
|
|
107
|
+
|
|
92
108
|
async def _create_connection_to_one_server(
|
|
93
109
|
self, server: ConnectionParameters
|
|
94
110
|
) -> tuple[AbstractConnection, ConnectionParameters] | None:
|
|
@@ -119,7 +135,7 @@ class ConnectionManager:
|
|
|
119
135
|
lifespan = self.lifespan_factory(
|
|
120
136
|
connection=connection,
|
|
121
137
|
connection_parameters=connection_parameters,
|
|
122
|
-
set_heartbeat_interval=self.
|
|
138
|
+
set_heartbeat_interval=self._restart_heartbeat_tasks,
|
|
123
139
|
)
|
|
124
140
|
|
|
125
141
|
try:
|
|
@@ -152,7 +168,7 @@ class ConnectionManager:
|
|
|
152
168
|
self._active_connection_state = connection_result
|
|
153
169
|
if not is_initial_call:
|
|
154
170
|
LOGGER.warning(
|
|
155
|
-
"reconnected after
|
|
171
|
+
"reconnected after connection failure. connection_parameters: %s",
|
|
156
172
|
connection_result.lifespan.connection_parameters,
|
|
157
173
|
)
|
|
158
174
|
return connection_result
|
|
@@ -162,11 +178,12 @@ class ConnectionManager:
|
|
|
162
178
|
|
|
163
179
|
raise FailedAllConnectAttemptsError(retry_attempts=self.connect_retry_attempts, issues=connection_issues)
|
|
164
180
|
|
|
165
|
-
def _clear_active_connection_state(self) -> None:
|
|
181
|
+
def _clear_active_connection_state(self, error_reason: ConnectionLostError) -> None:
|
|
166
182
|
if not self._active_connection_state:
|
|
167
183
|
return
|
|
168
184
|
LOGGER.warning(
|
|
169
|
-
"connection lost. connection_parameters: %s",
|
|
185
|
+
"connection lost. reason: %s, connection_parameters: %s",
|
|
186
|
+
error_reason.reason,
|
|
170
187
|
self._active_connection_state.lifespan.connection_parameters,
|
|
171
188
|
)
|
|
172
189
|
self._active_connection_state = None
|
|
@@ -176,8 +193,8 @@ class ConnectionManager:
|
|
|
176
193
|
connection_state = await self._get_active_connection_state()
|
|
177
194
|
try:
|
|
178
195
|
return connection_state.connection.write_heartbeat()
|
|
179
|
-
except ConnectionLostError:
|
|
180
|
-
self._clear_active_connection_state()
|
|
196
|
+
except ConnectionLostError as error:
|
|
197
|
+
self._clear_active_connection_state(error)
|
|
181
198
|
|
|
182
199
|
raise FailedAllWriteAttemptsError(retry_attempts=self.write_retry_attempts)
|
|
183
200
|
|
|
@@ -186,8 +203,8 @@ class ConnectionManager:
|
|
|
186
203
|
connection_state = await self._get_active_connection_state()
|
|
187
204
|
try:
|
|
188
205
|
return await connection_state.connection.write_frame(frame)
|
|
189
|
-
except ConnectionLostError:
|
|
190
|
-
self._clear_active_connection_state()
|
|
206
|
+
except ConnectionLostError as error:
|
|
207
|
+
self._clear_active_connection_state(error)
|
|
191
208
|
|
|
192
209
|
raise FailedAllWriteAttemptsError(retry_attempts=self.write_retry_attempts)
|
|
193
210
|
|
|
@@ -197,15 +214,15 @@ class ConnectionManager:
|
|
|
197
214
|
try:
|
|
198
215
|
async for frame in connection_state.connection.read_frames():
|
|
199
216
|
yield frame
|
|
200
|
-
except ConnectionLostError:
|
|
201
|
-
self._clear_active_connection_state()
|
|
217
|
+
except ConnectionLostError as error:
|
|
218
|
+
self._clear_active_connection_state(error)
|
|
202
219
|
|
|
203
220
|
async def maybe_write_frame(self, frame: AnyClientFrame) -> bool:
|
|
204
221
|
if not self._active_connection_state:
|
|
205
222
|
return False
|
|
206
223
|
try:
|
|
207
224
|
await self._active_connection_state.connection.write_frame(frame)
|
|
208
|
-
except ConnectionLostError:
|
|
209
|
-
self._clear_active_connection_state()
|
|
225
|
+
except ConnectionLostError as error:
|
|
226
|
+
self._clear_active_connection_state(error)
|
|
210
227
|
return False
|
|
211
228
|
return True
|
|
@@ -14,6 +14,8 @@ class Error(Exception):
|
|
|
14
14
|
class ConnectionLostError(Error):
|
|
15
15
|
"""Raised in stompman.AbstractConnection—and handled in stompman.ConnectionManager, therefore is private."""
|
|
16
16
|
|
|
17
|
+
reason: Exception | str
|
|
18
|
+
|
|
17
19
|
|
|
18
20
|
@dataclass(frozen=True, kw_only=True, slots=True)
|
|
19
21
|
class ConnectionConfirmationTimeout:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|