fix: deadlock on processNodeWithBuffer

This commit is contained in:
Adhiraj Singh
2022-11-07 17:21:32 +05:30
parent 02f9df5de4
commit 9e3c2082de

View File

@@ -546,7 +546,6 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
await sendReceipt(msg.key.remoteJid!, participant!, [msg.key.id!], type) await sendReceipt(msg.key.remoteJid!, participant!, [msg.key.id!], type)
// send ack for history message // send ack for history message
const isAnyHistoryMsg = getHistoryMsg(msg.message!) const isAnyHistoryMsg = getHistoryMsg(msg.message!)
if(isAnyHistoryMsg) { if(isAnyHistoryMsg) {
@@ -619,16 +618,28 @@ export const makeMessagesRecvSocket = (config: SocketConfig) => {
/// processes a node with the given function /// processes a node with the given function
/// and adds the task to the existing buffer if we're buffering events /// and adds the task to the existing buffer if we're buffering events
const processNodeWithBuffer = ( const processNodeWithBuffer = async(
node: BinaryNode, node: BinaryNode,
identifier: string, identifier: string,
exec: (node: BinaryNode) => Promise<any> exec: (node: BinaryNode) => Promise<any>
) => { ) => {
const task = exec(node) const started = ev.buffer()
.catch(err => onUnexpectedError(err, identifier)) if(started) {
await execTask()
if(started) {
await ev.flush()
}
} else {
const task = execTask()
ev.processInBuffer(task) ev.processInBuffer(task)
} }
function execTask() {
return exec(node)
.catch(err => onUnexpectedError(err, identifier))
}
}
// called when all offline notifs are handled // called when all offline notifs are handled
ws.on('CB:ib,,offline', async(node: BinaryNode) => { ws.on('CB:ib,,offline', async(node: BinaryNode) => {
const child = getBinaryNodeChild(node, 'offline') const child = getBinaryNodeChild(node, 'offline')