create_unix_server() removes listening unix socket, potentially from other process
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
I made a mistake leading to reusing the same unix socket path for multiple Python processes, then as a surprise realized only the last process's unix socket listening, and none will be listening if the last process stopped.
I then realized this was implemented in https://github.com/python/asyncio/pull/441 for https://bugs.python.org/issue28399 which isn't clear on why deleting the original unix socket make sense. Assumingly it is for removing old unix socket files that's not in use, but apparently it can be removing listening sockets as well.
I don't think this should be intended behavior but open to any comment. Thanks.
To reproduce, with repro.py as below:
import os
import asyncio
class IdentityProtocol(asyncio.Protocol):
"""a protocol that politely replies server's pid then close connection"""
def connection_made(self, transport):
print('got new connection')
transport.write(b'hello from pid=%d\r\n' % os.getpid())
transport.close()
async def main():
server = await asyncio.get_running_loop().create_unix_server(
lambda: IdentityProtocol(), 'duplicatedpath.sock'
)
async with server:
await server.serve_forever()
asyncio.run(main())
run two of such instances in separate terminals for the same working directory, and after each process created, use nc -CU duplicatedpath.sock which should simply show the pid of the last python process and exit.
CPython versions tested on:
3.10
Operating systems tested on:
Linux
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện hành vi với repro.py được cung cấp và các lệnh nc trên Linux, sau đó lần theo asyncio.create_unix_server() và xem xét PR 441 cùng issue 28399 được liên kết. Công việc được xem là hoàn tất khi hành vi dọn dẹp socket không còn xóa Unix socket đang lắng nghe của một tiến trình khác, đồng thời kịch bản được báo cáo được bao phủ bởi một bài kiểm thử hồi quy.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- networking
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100