Hook can run twice if registered with register_hook
lnedry opened this issue · comments
Describe the bug
If a hook is registered with register_hook, without using a unique function name, the hook will run twice.
Expected behavior
Based on the Plugin Run Order example in the Plugin documentation I would expect the hook to only run once.
Steps To Reproduce
It can be reproduced with this simple plugin:
exports.register = function () {
this.register_hook('connect', 'hook_connect', -100);
};
exports.hook_connect = function (next, connection) {
connection.loginfo(this, 'hook registration test');
return next();
}
Haraka help also shows that the hook in my example will run twice:
Plugin Method Prio T/O
--------------------------------------------------------------------------------
hook_registration_test hook_connect -100 30
hook_registration_test hook_connect 0 30
System Info:
Haraka | Haraka.js — Version: 3.0.3 |
---|---|
Node | v20.11.1 |
OS | Linux mx 5.10.0-27-amd64 #1 SMP Debian 5.10.205-2 (2023-12-31) x86_64 GNU/Linux |
openssl | OpenSSL 1.1.1w 11 Sep 2023 |
Hook can run twice if registered with register_hook
Yep. I thought that was clear in the Register A Hook section a few paragraphs higher. The example uses both methods, so why wouldn't it get registered twice? There are legit reasons to register a hook twice. I'm closing the issue because IMO, it's not an issue. Conversation can continue. A PR that updates the docs to be more explicit is welcome.