fix when kill child process, child process ANR - move the execution of pipeForRead.close() before the await statement.

This commit is contained in:
geekgeekrun
2024-11-23 13:29:49 +08:00
parent 015c141c1a
commit 830affa44c
@@ -105,20 +105,17 @@ export function runAutoChatWithDaemon() {
const pipeForReadWithJsonParser = pipeForRead.pipe(JSONStream.parse()) const pipeForReadWithJsonParser = pipeForRead.pipe(JSONStream.parse())
pipeForReadWithJsonParser?.on('data', async function waitForCanRun(data) { pipeForReadWithJsonParser?.on('data', async function waitForCanRun(data) {
if (data.type === 'GEEK_AUTO_START_CHAT_CAN_BE_RUN') { if (data.type === 'GEEK_AUTO_START_CHAT_CAN_BE_RUN') {
const ds = await initDb(getPublicDbFilePath())
const autoStartChatRunRecord = new AutoStartChatRunRecord()
autoStartChatRunRecord.date = new Date()
const autoStartChatRunRecordRepository = ds.getRepository(AutoStartChatRunRecord)
const result = await autoStartChatRunRecordRepository.save(autoStartChatRunRecord)
pipeForReadWithJsonParser.off('data', waitForCanRun) pipeForReadWithJsonParser.off('data', waitForCanRun)
clearSuicideTimer() clearSuicideTimer()
runWithDaemon({ runRecordId: result.id })
// if don't call close, when kill child process, child process will ANR. // if don't call close, when kill child process, child process will ANR.
pipeForRead.close() pipeForRead.close()
const ds = await initDb(getPublicDbFilePath())
const autoStartChatRunRecord = new AutoStartChatRunRecord()
autoStartChatRunRecord.date = new Date()
const autoStartChatRunRecordRepository = ds.getRepository(AutoStartChatRunRecord)
const result = await autoStartChatRunRecordRepository.save(autoStartChatRunRecord)
runWithDaemon({ runRecordId: result.id })
} }
}) })
process.on('SIGINT', () => { process.on('SIGINT', () => {