diff options
author | Jerome Flesch <ext-jerome.flesch@flowbird.group> | 2018-10-03 16:04:37 +0200 |
---|---|---|
committer | Jerome Flesch <ext-jerome.flesch@flowbird.group> | 2018-10-03 16:04:37 +0200 |
commit | c83599a1089ba66718d355b2478722479cc86028 (patch) | |
tree | e3d097a8ab5ab2d7fbdefcacaa67adef63be7508 | |
parent | a27715f322bb08b1fccffebab776c94df50057e9 (diff) | |
download | pyserial-git-c83599a1089ba66718d355b2478722479cc86028.tar.gz |
rfc2217/close(): fix race-condition: when stopping the read loop, do not set self._thread = None inside the thread itself as there may be a race-condition with the method close().
The method close() closes the socket, which stops the read loop. When the read loop stops, it set self._thread to None,
but if it set to None while close() is right between between the execution of "if self._thread:" and "self._thread.join()",
close() will raise an AttributeError.
Signed-off-by: Jerome Flesch <ext-jerome.flesch@flowbird.group>
-rw-r--r-- | serial/rfc2217.py | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/serial/rfc2217.py b/serial/rfc2217.py index d962c1e..53a2f43 100644 --- a/serial/rfc2217.py +++ b/serial/rfc2217.py @@ -613,7 +613,7 @@ class Serial(SerialBase): try: timeout = Timeout(self._timeout) while len(data) < size: - if self._thread is None: + if self._thread is None or not self._thread.is_alive(): raise SerialException('connection failed (reader thread died)') buf = self._read_buffer.get(True, timeout.time_left()) if buf is None: @@ -790,7 +790,6 @@ class Serial(SerialBase): self._telnet_negotiate_option(telnet_command, byte) mode = M_NORMAL finally: - self._thread = None if self.logger: self.logger.debug("read thread terminated") |