Fix Peertube crash when stopping the BOSH proxy.
This commit is contained in:
parent
de179e90d3
commit
507da6e042
@ -236,12 +236,12 @@ async function ensureProsodyNotRunning (options: RegisterServerOptions): Promise
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug('Removing proxy route')
|
||||||
|
await disableProxyRoute(options)
|
||||||
|
|
||||||
logger.debug('Calling prosodyctl to stop the process')
|
logger.debug('Calling prosodyctl to stop the process')
|
||||||
const status = await prosodyCtl(options, 'stop')
|
const status = await prosodyCtl(options, 'stop')
|
||||||
logger.info(`ProsodyCtl command returned: ${status.message}`)
|
logger.info(`ProsodyCtl command returned: ${status.message}`)
|
||||||
|
|
||||||
logger.debug('Removing proxy route')
|
|
||||||
await disableProxyRoute(options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
@ -313,24 +313,19 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
async function disableProxyRoute ({ peertubeHelpers }: RegisterServerOptions): Promise<void> {
|
async function disableProxyRoute ({ peertubeHelpers }: RegisterServerOptions): Promise<void> {
|
||||||
return new Promise((resolve) => {
|
// Note: I tried to promisify the httpbind proxy closing (by waiting for the callback call).
|
||||||
try {
|
// But this seems to never happen, and stucked the plugin uninstallation.
|
||||||
currentProsodyProxyInfo = null
|
// So I don't wait.
|
||||||
if (!currentHttpBindProxy) {
|
try {
|
||||||
resolve()
|
currentProsodyProxyInfo = null
|
||||||
return
|
if (currentHttpBindProxy) {
|
||||||
}
|
peertubeHelpers.logger.info('Closing the proxy...')
|
||||||
peertubeHelpers.logger.debug('Closing the proxy...')
|
currentHttpBindProxy.close()
|
||||||
currentHttpBindProxy.close(() => {
|
|
||||||
peertubeHelpers.logger.debug('The proxy is closed.')
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
currentHttpBindProxy = null
|
currentHttpBindProxy = null
|
||||||
} catch (err) {
|
|
||||||
peertubeHelpers.logger.error('Seems that the http bind proxy close has failed: ' + (err as string))
|
|
||||||
resolve()
|
|
||||||
}
|
}
|
||||||
})
|
} catch (err) {
|
||||||
|
peertubeHelpers.logger.error('Seems that the http bind proxy close has failed: ' + (err as string))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function enableProxyRoute (
|
async function enableProxyRoute (
|
||||||
@ -343,11 +338,27 @@ async function enableProxyRoute (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentProsodyProxyInfo = prosodyProxyInfo
|
currentProsodyProxyInfo = prosodyProxyInfo
|
||||||
logger.debug('Creating a new http bind proxy')
|
|
||||||
|
logger.info('Creating a new http bind proxy')
|
||||||
currentHttpBindProxy = createProxyServer({
|
currentHttpBindProxy = createProxyServer({
|
||||||
target: 'http://localhost:' + prosodyProxyInfo.port + '/http-bind',
|
target: 'http://localhost:' + prosodyProxyInfo.port + '/http-bind',
|
||||||
ignorePath: true
|
ignorePath: true
|
||||||
})
|
})
|
||||||
|
currentHttpBindProxy.on('error', (err, req, res) => {
|
||||||
|
// We must handle errors, otherwise Peertube server crashes!
|
||||||
|
logger.error(
|
||||||
|
'The proxy got an error ' +
|
||||||
|
'(this can be normal if you updated/uninstalled the plugin, or shutdowned peertube while users were chatting): ' +
|
||||||
|
err.message
|
||||||
|
)
|
||||||
|
if ('writeHead' in res) {
|
||||||
|
res.writeHead(500)
|
||||||
|
}
|
||||||
|
res.end('')
|
||||||
|
})
|
||||||
|
currentHttpBindProxy.on('close', () => {
|
||||||
|
logger.info('Got a close event for the http bind proxy')
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user