Compare commits

...

1 Commits

Author SHA1 Message Date
Julien Fontanet
7e65a139ab fix(proxy/api): allow methods to not prevent proxy shutdown 2024-10-21 00:02:46 +02:00
3 changed files with 19 additions and 12 deletions

View File

@@ -89,7 +89,21 @@ export default class Api {
let result
try {
result = await zone.run(() => this._call(body.method, body.params))
result = await zone.run(() => {
const { method, params } = body
debug(`call: ${method}()`, { method, params })
const fn = this._methods[method]
if (fn === undefined) {
throw new MethodNotFound(method)
}
if (fn.unref) {
ctx.req.socket.unref()
}
return fn(params)
})
} catch (error) {
ctx.set('Content-Type', 'application/json')
ctx.body = formatError(body.id, error)
@@ -236,7 +250,7 @@ export default class Api {
})
}
addMethod(name, method, { description, params = {}, result: resultSchema } = {}) {
addMethod(name, method, { description, params = {}, result: resultSchema, unref = false } = {}) {
const methods = this._methods
if (name in methods) {
@@ -276,6 +290,7 @@ export default class Api {
m.description = description
m.params = params
m.result = resultSchema
m.unref = unref
methods[name] = m
@@ -318,15 +333,6 @@ export default class Api {
return once => forOwn(removes, remove => remove())
}
_call(method, params = {}) {
debug(`call: ${method}()`, { method, params })
const fn = this._methods[method]
if (fn === undefined) {
throw new MethodNotFound(method)
}
return fn(params)
}
#compileSchema(schema) {
if (schema === undefined) {
return stubTrue

View File

@@ -154,7 +154,7 @@ export default class Appliance {
params: { channel: { type: 'string' } },
},
],
upgrade: () => callUpdate({ upgrade: true }),
upgrade: [() => callUpdate({ upgrade: true }), { unref: true }],
},
},
})

View File

@@ -39,6 +39,7 @@
<!--packages-start-->
- @xen-orchestra/log minor
- @xen-orchestra/proxy patch
- @xen-orchestra/mixin minor
- @xen-orchestra/xapi patch
- xo-cli minor