diff --git a/pr_body2.md b/pr_body2.md new file mode 100644 index 000000000..2eddbf14d --- /dev/null +++ b/pr_body2.md @@ -0,0 +1,16 @@ +In `TCPClient._create_stream`, if `IOStream()` constructor raises `OSError`, the except handler references `stream` which was never assigned: + +```python +try: + stream = IOStream(socket_obj, max_buffer_size=max_buffer_size) +except OSError as e: + fu = Future() + fu.set_exception(e) + return stream, fu # NameError: 'stream' is not defined +``` + +This causes a `NameError` that masks the original `OSError`, making it impossible to diagnose the root cause from the traceback. + +Additionally the socket object would be leaked since it's never closed in the error path. + +Fixed by returning the `socket_obj` instead of the undefined `stream` variable, and closing the socket before returning. diff --git a/tornado/locale.py b/tornado/locale.py index abd8668c6..f3b80b2b8 100644 --- a/tornado/locale.py +++ b/tornado/locale.py @@ -433,7 +433,7 @@ def format_date( def format_day( self, date: datetime.datetime, gmt_offset: int = 0, dow: bool = True - ) -> bool: + ) -> str: """Formats the given date as a day of week. Example: "Monday, January 22". You can remove the day of week with