Skip to content

Make whats-in-port and clear-port agree on what is in a port #796

Description

@purinkle

bin/clear-port and bin/whats-in-port are a pair. Since #789 they no longer
agree on what "in the port" means.

$ grep lsof bin/clear-port
  lsof -ti4TCP:"$1" -sTCP:LISTEN | xargs -r kill

$ grep lsof bin/whats-in-port
  lsof -ni4TCP:"$1"

clear-port now looks only at the listening process. whats-in-port still
lists every socket on that port, so it includes established connections. A
browser with the page open shows up there.

The result is that whats-in-port 3000 can list processes that clear-port 3000 will not touch. Someone reads the first, runs the second, and the thing
they saw is still running.

#789 was right to narrow clear-port. Killing a browser because it had the
page open was the bug. The question is whether whats-in-port should narrow
to match.

Two ways to settle it:

  • Add -sTCP:LISTEN to whats-in-port, so both answer the same question.
    Simple, and the pair stays honest.
  • Leave it wide on purpose, because seeing every holder of a port is useful
    when you are working out what is going on. If we choose this, say so in a
    comment in both scripts, so the difference reads as deliberate.

Either is defensible. Having it happen by accident is not.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions