Skip to content

Add new ext onPostResponse#4073

Merged
hueniverse merged 2 commits intomasterfrom
onPostResponse
Mar 19, 2020
Merged

Add new ext onPostResponse#4073
hueniverse merged 2 commits intomasterfrom
onPostResponse

Conversation

@hueniverse
Copy link
Copy Markdown
Contributor

@hueniverse hueniverse commented Mar 15, 2020

This will eventually replace the response event (removed next major). Related to feedback from #4053.

@hueniverse hueniverse added the feature New functionality or improvement label Mar 15, 2020
@hueniverse hueniverse added this to the 19.2.0 milestone Mar 15, 2020
@hueniverse hueniverse self-assigned this Mar 15, 2020
Copy link
Copy Markdown
Contributor

@kanongil kanongil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, especially if updated to better accommodate "slow" onPostResponse handlers, that can be used to apply tail logic.

Comment on lines 390 to +400
const realm = ext.realm;
const bind = ext.bind || realm.settings.bind;
const response = await this._core.toolkit.execute(ext.func, this, { bind, realm, timeout: ext.timeout, name: event.type });
const response = await this._core.toolkit.execute(ext.func, this, { bind, realm, timeout: ext.timeout, name: event.type, ignoreResponse: options.ignoreResponse });

if (options.ignoreResponse) {
if (Boom.isBoom(response)) {
this._log(['ext', 'error'], response);
}

continue;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic needs to be executed in parallel for onPostResponse handlers. Otherwise the timing can get messed up.

This will make onPostResponse a good place to apply tail logic, allowing errors to be logged and all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow. Can you give an example where serial processing is going to be a problem here (and how is it different from current response event)?

Copy link
Copy Markdown
Contributor

@kanongil kanongil Mar 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Say you add an onPostResponse handler to increment a value in your db, and a handler to log to stdout. The log handler would be delayed an indeterminate amount of time while the previous handler talks to the db. This will in turn mean that the log entry will appear later than intended, and that multiple such log entries could appear out of order.

Also, the current response event is essentially a parallel handler, since it is a fire and forget thing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The await lets you enforce order but it is not required. There is nothing blocking you for implementing extension handlers that return right away and schedule work for a next tick. I'm inclined not to special case this to parallel execution because it makes reasoning about ext order harder. Keeping it the same means the same plugin order logic applies, etc.

It is probably worth documenting it so that people will write smarter handlers if they rely on getting quick notification of the event and then doing something.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense that you want to keep the existing reasoning about how it runs, though I believe it can cause issues.

Maybe an extension isn't the right fit for this? Most of the h properties / methods doesn't make sense anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a perfect fit but it benefits for a lot of other similar facilities that I think it still works. We'll see how it goes.

@hueniverse hueniverse merged commit a61f780 into master Mar 19, 2020
@hueniverse hueniverse deleted the onPostResponse branch March 19, 2020 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New functionality or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants