Skip to content

implementing "unclosed-ressource" warning #692

Description

@clemgbld

The goal would be to implement a new probe that detect unclosed ressource for example:

const fs = require('fs/promises');

let fileHandle;
try {
  fileHandle = await fs.open('example.txt', 'r');
  // ... perform operations
await fileHandle.close(); // Releases the file resource
} catch(e) {
  console.log(e.message);
 // if an error occurs we don't release the file resource
 throw error;
}
  • A list of modules to cover would be:

File descriptor | (fs) fileHandle.close() / fs.close(fd)
Streams | stream.destroy() or stream.end()
Net/HTTP sockets & servers | socket.destroy(), server.close()
Timers | clearTimeout() / clearInterval(), or timer.unref()
Worker threads | worker.terminate()
DB pool connections | client.release() (library-specific)

  • Edge cases to consider:

Since node 24 we can use Symbol.dispose, Symbol.asyncDispose with the keyword using.

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