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-10-26 10:10:24 +08:00
parent 015c141c1a
commit 830affa44c

View File

@@ -105,20 +105,17 @@ export function runAutoChatWithDaemon() {
const pipeForReadWithJsonParser = pipeForRead.pipe(JSONStream.parse())
pipeForReadWithJsonParser?.on('data', async function waitForCanRun(data) {
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)
clearSuicideTimer()
runWithDaemon({ runRecordId: result.id })
// if don't call close, when kill child process, child process will ANR.
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', () => {