Code Monkey home page Code Monkey logo

Comments (4)

isaacs avatar isaacs commented on August 26, 2024

This module already makes a best-effort attempt to unlock files on process exit.

https://github.com/npm/lockfile/blob/master/lockfile.js#L33-L37

from lockfile.

fritx avatar fritx commented on August 26, 2024

Thanks for reply, but when I taskkill the process, the unlock didnt work.
Maybe I misunderstood the use case of file lock?

I want to lock a user file after user login,
and make sure the lock removed when the same process quit (including taskkill, etc)

from lockfile.

isaacs avatar isaacs commented on August 26, 2024

The process.on('exit') event doesn't fire if the process is killed by a unix signal.

You can use the module signal-exit, and add this:

var signalExit = require('signal-exit')
signalExit(function (code, signal) {
  if (signal)
    process.emit('exit')
})

var lockfile = require('lockfile')
// do whatever with lock files

Doing this requires that the program add os-level listeners to every possible fatal signal, and do some other hoop-jumping to make sure it doesn't accidentally prevent the exit when the signal should be fatal. That's what the signal-exit module does, but it would be excessive to do that in this module.

from lockfile.

fritx avatar fritx commented on August 26, 2024

Thanks! But I guess some of these signals are inavailable in Windows, :/ as well as killing the process from task monitor?

from lockfile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.