Skip to content

create_unix_server() removes listening unix socket, potentially from other process #121252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tdihp opened this issue Jul 2, 2024 · 0 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@tdihp
Copy link

tdihp commented Jul 2, 2024

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 python/asyncio#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

@tdihp tdihp added the type-bug An unexpected behavior, bug, or error label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant