Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not crash if nested plugin does not call next #252

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,16 @@ Plugin.prototype.loadedSoFar = function () {
this._error = afterErr
this.queue.pause()

if (afterErr) {
debug('rejecting promise', this.name, afterErr)
this._promise.reject(afterErr)
} else {
debug('resolving promise', this.name)
this._promise.resolve()
if (this._promise) {
if (afterErr) {
debug('rejecting promise', this.name, afterErr)
this._promise.reject(afterErr)
} else {
debug('resolving promise', this.name)
this._promise.resolve()
}
this._promise = null
}
this._promise = null

process.nextTick(callback, afterErr)
})
Expand Down
42 changes: 42 additions & 0 deletions test/plugin-timeout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,45 @@ test('timeout without calling next in ready and rethrowing the error', (t) => {

app.start()
})

test('nested timeout do not crash - callbacks', (t) => {
t.plan(4)
const app = boot({}, {
timeout: 10 // 10 ms
})
app.use(one)
function one (app, opts, next) {
app.use(two).after(next)
}

function two (app, opts, next) {
// do not call next on purpose
}
app.ready((err) => {
t.ok(err)
t.equal(err.fn, one)
t.equal(err.message, message('one')) // TODO: should be 'two'
Copy link
Member

Choose a reason for hiding this comment

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

So this means we should in the future be able to show that two failed right?

t.equal(err.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
})
})

test('nested timeout do not crash - await', (t) => {
t.plan(4)
const app = boot({}, {
timeout: 10 // 10 ms
})
app.use(one)
async function one (app, opts) {
await app.use(two)
}

function two (app, opts, next) {
// do not call next on purpose
}
app.ready((err) => {
t.ok(err)
t.equal(err.fn, one)
t.equal(err.message, message('one')) // TODO: should be 'two'
t.equal(err.code, 'AVV_ERR_PLUGIN_EXEC_TIMEOUT')
})
})
Loading