[BUG] disconnect on average 1 hour DisconnectReason.bad Session == 500
athilasb opened this issue · comments
Mine, after an average of 1 hour of disconnection, enters this if DisconnectReason.badSession == 500
My version "@whiskeysockets/baileys": "6.7.4",
const { state, saveCreds } = await useMultiFileAuthState("./main-session/" + process.env.INSTANCE);
Mai = MaiConnect({
version: [2, 2413, 1],
logger: pin({ level: "silent" }),
printQRInTerminal: false, // Disabled here, as we will use qrcode-terminal to display
browser: Browsers.macOS("Desktop"),
auth: state,
});
// Handling credentials update
Mai.ev.on("creds.update", saveCreds);
Mai.ev.on("connection.update", (update) => {
const { connection, lastDisconnect, qr } = update;
if (connection === "close") {
let reason = lastDisconnect.error
? lastDisconnect?.error?.output.statusCode
: 0;
if (reason === DisconnectReason.badSession) {
deleteSession("Invalid session, restarting...." + DisconnectReason.badSession + JSON.stringify(Mai.user))
qrGenerated = true;
startMai();
}
}
});
Can anyone help me with this error please?
bad session = your code / storage, clear creds ands read new qrcode
That's right But this only happens in a few numbers, Can you help me how can I stop giving this bad session problem ?
In version 6.6.0 this problem does not occur
I`m having the same issue, after update to V6.7.5. I downgrade to V6.6.0 (I was using this version before the update) but a few numbers are stopping and not working well.
@athilasb do you fix it?
this error did not happen in version 6.6.0
I have some numbers connectds and 4 of these numbers are stopping to work and need to recreate the connection,
other ten numbers are working well.
It was working well but after update to 6.7.5 it starts to happens but now I i already downgrade to 6.6.0 and the same behavior are happening.
I already read the qr code and it is still stopping.
If you fall into the if (reason === DisconnectReason.badSession) or if (reason === DisconnectReason.connectionReplaced) or if (reason === DisconnectReason.loggedOut) or if (lastDisconnect?. error?. output?. statusCode === DisconnectReason.conflict) There's nothing to do, you have to regenerate the qrCode, Do you check if it falls into any of these errors?
if (connection === "close") {
let reason = lastDisconnect.error
? lastDisconnect?.error?.output.statusCode
: 0;
if (reason === DisconnectReason.badSession) {
attr = {
reason: "Invalid session, restarting....",
code: DisconnectReason.badSession,
user : JSON.stringify(Mai.user)
};
deleteSession(attr)
qrGenerated = true;
startMai();
//process.exit(0);
return
} else if (reason === DisconnectReason.connectionClosed) {
console.log("Connection closed, reconnecting....");
status = "Connection closed, reconnecting....";
startMai();
} else if (reason === DisconnectReason.connectionLost) {
console.log("Lost connection to server, reconnecting...");
status = "Lost connection to server, reconnecting...";
startMai();
} else if (reason === DisconnectReason.connectionReplaced) {
if (unknown >= 10) {
attr = {
reason: "Connection replaced, please delete the session and scan again.",
code: DisconnectReason.connectionReplaced,
user : JSON.stringify(Mai.user)
};
deleteSession(attr)
qrGenerated = true;
startMai();
//process.exit(0);
return
} else {
unknown++;
startMai();
console.log("Unexpected: Connection replaced, reconnecting...");
}
} else if (reason === DisconnectReason.loggedOut) {
attr = {
reason: "Disconnected By Device, please delete the session and scan again.",
code: DisconnectReason.loggedOut,
user : JSON.stringify(Mai.user)
};
deleteSession(attr)
qrGenerated = true;
status = "Device disconnected";
startMai();
//process.exit(0);
return
} else if (reason === DisconnectReason.restartRequired) {
console.log("Restart required, restarting..." + JSON.stringify(Mai.user));
status = "Valid restart, restarting...";
startMai();
} else if (reason === DisconnectReason.timedOut) {
console.log("Connection timed out, reconnecting...");
status = "Connection timed out, reconnecting...";
startMai();
} else if (lastDisconnect?.error?.output?.statusCode === DisconnectReason.conflict) {
if (unknown >= 10) {
attr = {
reason: "Conflicting connection, restarting....",
code: DisconnectReason.conflict,
user : JSON.stringify(Mai.user)
};
deleteSession(attr);
qrGenerated = true;
startMai();
//process.exit(0);
return
} else {
unknown++;
//
//console.log("Conflicting connection, restarting....");
}
} else {
if (unknown >= 10) {
attr = {
reason: "Unknown disconnection reason",
code: "",
user : JSON.stringify(Mai.user)
}
deleteSession(attr)
qrGenerated = true;
startMai();
//process.exit(0);
return
} else {
unknown++;
startMai();
}
}
if (presenceUpdateInterval) {
clearInterval(presenceUpdateInterval);
}
socket('log', status);
socket('status', checkStatus);
checkStatus = false;
}
ok, I will try it. I'm not checking all these cases.
I'm having the same issue on only few numbers: 1 hour after connected and then bad session error
I'm having the same issue it only fixed after restarting node reconnect again " it only happens with few numbers and average 1 hour , Any suggestion ?
Thanks .
Worse still, I didn't find a solution for this either, it will probably only be resolved with a library update.
Worse still, I didn't find a solution for this either, it will probably only be resolved with a library update.
Please if you find an solution for this let us know <3 .
warning yes
same issues here, 1 hour after connected and then bad session error
App 1260534 output: Connection Status: close
App 1260534 output: [*] Connection closed due to Error: Stream Errored (ack)
App 1260534 output: data: { tag: 'stream:error', attrs: {}, content: [ [Object] ] },
App 1260534 output: isBoom: true,
App 1260534 output: isServer: true,
App 1260534 output: output: {
App 1260534 output: statusCode: 500,
App 1260534 output: payload: {
App 1260534 output: statusCode: 500,
App 1260534 output: error: 'Internal Server Error',
App 1260534 output: message: 'An internal server error occurred'
App 1260534 output: },
App 1260534 output: headers: {}
App 1260534 output: }
App 1260534 output: } , reconnecting true
App 1260534 output: [*] Bad Session, Please Scan Again!
my code is:
sock.ev.on("connection.update", async (update) => {
const { connection, lastDisconnect, isNewLogin, qr } = update;
if (connection) console.info("Connection Status: ", connection);
let reason = new Boom(lastDisconnect?.error)?.output?.statusCode;
if (connection === "close") {
const shouldReconnect = lastDisconnect.error?.output?.statusCode !== DisconnectReason.loggedOut;
console.log("[*] Connection closed due to ", lastDisconnect.error, ", reconnecting ", shouldReconnect);
if (reason === DisconnectReason.badSession) {
console.log(`[*] Bad Session, Please Scan Again!`);
}
}
})
this is known issue, we can wait for the fix later. in the meantime, shouldReconnect should do the job
Hi, any update on this issue?
any update ?
up
Up
+1