[issue42342] asyncio.open_connection(local_addr=('localhost', port)) fails with TypeError: AF_INET address must be a pair (host, port)

2020-11-13 Thread Ed Catmur


New submission from Ed Catmur :

Context: CentOS 7.8.2003, Python 3.8 from SCL. localhost has IPv4 and IPv6 
bindings, IPv6 first:
$ python -c "import 
socket;print(socket.getaddrinfo('localhost',0,type=socket.SOCK_STREAM))"
[(, , 6, '', ('::1', 0, 
0, 0)), (, , 6, '', 
('127.0.0.1', 0))]

import asyncio
async def main():
await asyncio.open_connection('localhost', 9990, local_addr=('localhost', 
9991))
asyncio.run(main())

Traceback (most recent call last):
  File "async.py", line 4, in 
asyncio.run(main())
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/runners.py", line 
43, in run
return loop.run_until_complete(main)
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/base_events.py", 
line 608, in run_until_complete
return future.result()
  File "async.py", line 3, in main
await asyncio.open_connection('10.10.10.10', 9990, local_addr=('localhost', 
9991))
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/streams.py", line 
52, in open_connection
transport, _ = await loop.create_connection(
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/base_events.py", 
line 1002, in create_connection
sock = await self._connect_sock(
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/base_events.py", 
line 904, in _connect_sock
sock.bind(laddr)
TypeError: AF_INET address must be a pair (host, port)

It looks like this has a similar root cause to issue 35302 - we should be 
filtering local addrinfos by family for valid combinations.

--
components: asyncio
messages: 380874
nosy: asvetlov, ecatmur2, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.open_connection(local_addr=('localhost', port)) fails with 
TypeError: AF_INET address must be a pair (host, port)
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue42342>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42378] logging reopens file with same mode, possibly truncating

2020-11-16 Thread Ed Catmur


New submission from Ed Catmur :

If a logging.FileHandler is configured with mode='w', or if logging.basicConfig 
is called with filemode='w' (as suggested by the Basic Logging Tutorial 
https://docs.python.org/3/howto/logging.html#logging-basic-tutorial)
and if some code logs during shutdown, after logging has closed its handlers 
(asyncio is prone to do this, e.g.),
then logging.FileHandler._open will reopen the log file with the same mode as 
it was originally opened with, potentially truncating it and losing valuable 
information:

import atexit
atexit.register(lambda: logging.info("so long"))
import logging
logging.basicConfig(filename='test.log', filemode='w', level=logging.INFO)
logging.info("super important stuff")

$ python truncate.py
$ cat test.log
INFO:root:so long

I have a hunch that the fix to issue 26789 will potentially make things worse, 
as previously at least there was a chance that logging had been fully unloaded 
so that the call to open would fail.

https://stackoverflow.com/questions/39838616/why-is-python-logging-framework-losing-messages

--
components: Library (Lib)
messages: 381146
nosy: ecatmur2
priority: normal
severity: normal
status: open
title: logging reopens file with same mode, possibly truncating
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue42378>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com