haraka / Haraka

A fast, highly extensible, and event driven SMTP server
https://haraka.github.io
MIT License
5.08k stars 661 forks source link

fs watcher callback interaction #784

Closed msimerson closed 9 years ago

msimerson commented 9 years ago

this happened in the plugins/rcpt_to.in_host_list plugin:

Dec 17 18:07:00 filter1-mail haraka[40266]: [CRIT] [-] [core] TypeError: Cannot call method 'loginfo' of undefined
Dec 17 18:07:00 filter1-mail haraka[40266]: [CRIT] [-] [core]     at FSEvent.FSWatcher._handle.onchange (fs.js:1050:12)
Dec 17 18:07:00 filter1-mail haraka[40266]: [CRIT] [-] [core]     at FSWatcher.<anonymous> (/usr/local/lib/node_modules/Haraka/configfile.js:37:39)
Dec 17 18:07:00 filter1-mail haraka[40266]: [CRIT] [-] [core]     at exports.load_host_list (/usr/local/lib/node_modules/Haraka/plugins/rcpt_to.host_list_base.js:7:12)
Dec 17 18:07:00 filter1-mail node[40266]: [CRIT] [-] [core]     at FSWatcher.emit (events.js:98:17)

It happens immediately after the host_list file changes. I have temporarily worked around this by moving the function that loads the config (load_host_list) from the rcpt_to.host_list_base.js plugin into the rcpt_to.in_host_list.js plugin.

msimerson commented 9 years ago

Hmm, this may have nothing to do with inheritance:

Dec 17 16:19:06 node haraka[59474]: [INFO] [-] [core] Detected change, reloading /usr/local/haraka/config/karma.ini
Dec 17 16:19:06 node haraka[89450]: [INFO] [-] [core] Detected change, reloading /usr/local/haraka/config/karma.ini
Dec 17 16:19:06 node haraka[89450]: [CRIT] [-] [core] TypeError: Cannot call method 'loginfo' of undefined
Dec 17 16:19:06 node haraka[89450]: [CRIT] [-] [core]     at exports.load_karma_ini (/usr/local/lib/node_modules/Haraka/plugins/karma.js:28:12)
Dec 17 16:19:06 node haraka[89450]: [CRIT] [-] [core]     at FSWatcher.<anonymous> (/usr/local/lib/node_modules/Haraka/configfile.js:36:39)
Dec 17 16:19:06 node haraka[89450]: [CRIT] [-] [core]     at FSWatcher.emit (events.js:98:17)
Dec 17 16:19:06 node haraka[89450]: [CRIT] [-] [core]     at FSEvent.FSWatcher._handle.onchange (fs.js:1050:12)
Dec 17 16:19:06 node haraka[89450]: [NOTICE] [-] [core] Shutting down
Dec 17 16:19:06 node haraka[59474]: [CRIT] [-] [core] TypeError: Cannot call method 'loginfo' of undefined
Dec 17 16:19:06 node haraka[59474]: [CRIT] [-] [core]     at exports.load_karma_ini (/usr/local/lib/node_modules/Haraka/plugins/karma.js:28:12)
Dec 17 16:19:06 node haraka[59474]: [CRIT] [-] [core]     at FSWatcher.<anonymous> (/usr/local/lib/node_modules/Haraka/configfile.js:36:39)
Dec 17 16:19:06 node haraka[59474]: [CRIT] [-] [core]     at FSWatcher.emit (events.js:98:17)
Dec 17 16:19:06 node haraka[59474]: [CRIT] [-] [core]     at FSEvent.FSWatcher._handle.onchange (fs.js:1050:12)
Dec 17 16:19:06 node haraka[59474]: [NOTICE] [-] [core] Shutting down
smfreegard commented 9 years ago

Here's your bug:

    plugin.cfg = plugin.config.get('karma.ini', {
        booleans: [
            '+asn.enable',
        ],
    }, plugin.load_karma_ini);

It should be:

    plugin.cfg = plugin.config.get('karma.ini', {
        booleans: [
            '+asn.enable',
        ],
    }, function reload_config() {
        plugin.load_karma_ini(); 
    });
msimerson commented 9 years ago

Hmm, that change needs to be made in a few plugins then...

smfreegard commented 9 years ago

It's not a new requirement - it would never have worked like that. You were passing the body of the function instead of calling the method inside a closure. In the former case plugin becomes undefined because the function is called in the context of the caller.

msimerson commented 9 years ago

I understand the difference, right after you showed the example code. But there's still a few plugins that must be updated to be closures. I'll work on that...