Commit 5f5b427
committed
Raise exception when modbus unit unexpectedly closes connection
Raise an error when the modbus unit unexpectedly closes the connection
during a receive data operation without returning any data, and log a
warning if it does return some but not all data before closing the
connection. Detecting and handling this here ensures that
ModbusTcpClient._recv doesn't needlessly loop until it times out after
the stream is closed by the peer, and also makes it certain that a
response of b'' from ModbusTcpClient._recv means there was a timeout
and cannot mean that the peer closed the stream, as it could mean
before.
The previous behavior was to not identify the remote end closing the
socket, triggering a timeout, in turn causing the transaction manager
to treat it as the modbus unit returning a response with errors in
it (raising InvalidMessageReceivedException). This will now raise a
ConnectionException, which falls through to the client, bypassing the
retry mechanisms.
Note that https://docs.python.org/3/library/socket.html does not
contain a full description on the socket.recv method; see also pydoc
for socket.socket.recv.1 parent d4f5f9e commit 5f5b427
1 file changed
+38
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
243 | 248 | | |
244 | 249 | | |
245 | 250 | | |
| |||
270 | 275 | | |
271 | 276 | | |
272 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
273 | 281 | | |
274 | 282 | | |
275 | 283 | | |
| |||
286 | 294 | | |
287 | 295 | | |
288 | 296 | | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
289 | 326 | | |
290 | 327 | | |
291 | 328 | | |
| |||
0 commit comments