Skip to content

Socket is not closed after running IsInstalledCommand #526

@verakruhliakova

Description

@verakruhliakova

Calling device.isInstalled(pkg) leads to a socket leak.

If application calls this command in a loop, eventually app crashes with EMFILE: too many open files.

Checking occupied sockets shows that they hang in CLOSED state, but never actually released by the machine.

% lsof -i -l | grep "5037"
...
node    33919      503  188u  IPv4 0x359a2e226d9499af      0t0  TCP localhost:49446->localhost:5037 (CLOSED)
node    33919      503  189u  IPv4 0x359a2e226d6259af      0t0  TCP localhost:49364->localhost:5037 (CLOSED)
node    33919      503  190u  IPv4 0x359a2e226d8d8457      0t0  TCP localhost:49501->localhost:5037 (CLOSED)
node    33919      503  191u  IPv4 0x359a2e226d539457      0t0  TCP localhost:49648->localhost:5037 (CLOSED)
node    33919      503  192u  IPv4 0x359a2e226d2fef07      0t0  TCP localhost:49479->localhost:5037 (CLOSED)
node    33919      503  193u  IPv4 0x359a2e226d59ef07      0t0  TCP localhost:49400->localhost:5037 (CLOSED)
node    33919      503  194u  IPv4 0x359a2e226d63ff07      0t0  TCP localhost:49502->localhost:5037 (CLOSED)
node    33919      503  195u  IPv4 0x359a2e226d84d457      0t0  TCP localhost:49503->localhost:5037 (CLOSED)
node    33919      503  196u  IPv4 0x359a2e226d84c9af      0t0  TCP localhost:49450->localhost:5037 (CLOSED)
node    33919      503  197u  IPv4 0x359a2e226d0a3457      0t0  TCP localhost:49546->localhost:5037 (CLOSED)
...

Environment:
Node: v20.11.0
OS: MacOS 12.6.5

The reason to this issue is that command calls parser.readAscii() and never finishes reading the socket stream, which prevents socket from being closed.

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