python / python/cpython

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

Offen
#121,252 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, das Verhalten mit dem bereitgestellten repro.py und den nc-Befehlen unter Linux zu reproduzieren, verfolge dann asyncio.create_unix_server() weiter und prüfe den verlinkten PR 441 sowie Issue 28399. Erledigt ist die Aufgabe, wenn das Socket-Cleanup-Verhalten nicht mehr den lauschenden Unix-Socket eines anderen Prozesses entfernt und das gemeldete Szenario durch einen Regressionstest abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.