Skip to content

Getting 'TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined' on tail.unwatch() #19

Description

@lankesh

Here's stack trace:

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
    at makeCallback (fs.js:168:11)
    at Object.close (fs.js:427:14)
    at Tail.unwatch (/home/komal/projects/zestl/source_code/TwigMeServerApplication/docker/clients/python_error_logs/api/node_modules/always-tail/index.js:164:10)
    at Socket.<anonymous> (/home/komal/projects/zestl/source_code/TwigMeServerApplication/docker/clients/python_error_logs/api/services/tail_file.js:22:14)
    at Socket.emit (events.js:327:22)
    at TCP.<anonymous> (net.js:673:12) {
code: 'ERR_INVALID_CALLBACK'
}

Here's what I was trying to do

const TailFile = (req, res, next, filename) => {
    var Tail = require('always-tail');
    var fs   = require('fs');
    if (!fs.existsSync(filename)) {
        fs.writeFileSync(filename, "")
    };
    var tail = new Tail(filename, '\n');
    tail.on('line', function (data) {
        console.log("got line:", data);
        res.write(data)
    });
    tail.on('error', function (data) {
        console.log("error:", data);
    });
    tail.watch();

    res.header('Content-Type', 'text/event-stream');

    req.socket.on('close', () => {
        // This is not working
        tail.unwatch();
    });
};

I am getting error on tail.unwatch();

I wandered around the always-tail code and found that by changing following lines in always-tail/index.js's Tail.prototype.unwatch function, the error message is gone and my application stops crashing
Previous code
fs.close(self.fd);
Fixed code
fs.close(self.fd, function(){});

Previous code
fs.close(item.fd);
Fixed code
fs.close(item.fd, function(){});

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions