mysql: Cannot enqueue Query after invoking quit.
Hi I keep getting this error on my code and I don’t know how to fix it I’ve tried a lot of things. I don’t know but I think its a problem with connection.end()
even with it I still get this error. If anyone could help me fix this that would be great.
events.js:85
throw er; // Unhandled 'error' event
^
Error: Cannot enqueue Query after invoking quit.
at Protocol._validateEnqueue (C:\Users\Iain\Steambot\node_modules\mysql\lib\protocol\Protocol.js:202:16)
at Protocol._enqueue (C:\Users\Iain\Steambot\node_modules\mysql\lib\protocol\Protocol.js:135:13)
at Connection.query (C:\Users\Iain\Steambot\node_modules\mysql\lib\Connection.js:201:25)
at C:\Users\Iain\Steambot\EditedBotJS.js:139:17
at Request._callback (C:\Users\Iain\Steambot\node_modules\steam-market-pricing\index.js:32:13)
at Request.self.callback (C:\Users\Iain\Steambot\node_modules\request\request.js:198:22)
at Request.emit (events.js:110:17)
at Request.<anonymous> (C:\Users\Iain\Steambot\node_modules\request\request.js:1035:10)
at Request.emit (events.js:129:20)
at IncomingMessage.<anonymous> (C:\Users\Iain\Steambot\node_modules\request\request.js:962:12)
This is the code:
connection.query('SELECT COUNT(*) AS Total FROM incomingPlayers WHERE accountID=' + steamAccountID64, function(err, rows, fields) {
if (rows[0].Total == 0) {
if (offer.partner.getSteamID64() === config.admin || offer.itemsToGive.length === 0) {
console.log(steamAccountID64);
offer.accept(function(err) {
if (err) {
logger.error("Unable to accept offer " + offer.id + ": " + err.message);
} else {
logger.info("Offer accepted");
}
});
var numberofitems = offer.itemsToReceive.length;
for (var i = 0; i < numberofitems; i++) {
if (offer.itemsToReceive[i].appid == "730") {
var itemInfo = {
itemName: offer.itemsToReceive[i].market_hash_name,
assetID: offer.itemsToReceive[i].assetid,
iconURL: offer.itemsToReceive[i].icon_url,
accountID: steamAccountID64
};
connection.query('INSERT INTO incomingOffers SET ?', itemInfo);
market.getItemPrice(730, 'MP9 | Storm (Minimal Wear)', function(err, data) {
connection.query("UPDATE incomingOffers SET itemValue='" + data.lowest_price.replace('$','') + "' WHERE assetID='4361351533'");
});
console.log(itemInfo.itemName + " of ID:" + itemInfo.assetID + " was accepted for trade by user : " + steamAccountID64);
} else {
console.log("Attempted to add item of appid: " + offer.itemsToReceive[i].appid);
};
};
connection.query('INSERT INTO incomingPlayers SET ?', {
accountID: steamAccountID64,
itemCount: numberofitems
});
} else {
offer.decline(function(err) {
if (err) {
logger.error("Unable to decline offer " + offer.id + ": " + err.message);
} else {
console.log("Trade was declined from " + offer.partner.getSteamID64() + ", user is not admin or sent dodgy offer");
};
});
};
} else {
offer.decline(function(err) {
if (err) {
logger.error("Unable to decline offer " + offer.id + ": " + err.message);
} else {
console.log("Trade was declined from " + offer.partner.getSteamID64() + ", user already went in");
};
});
};
connection.end();
});
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 15 (6 by maintainers)
Hi! The error you provided is because you are chronologically calling
connection.query()
after you calledconnection.end()
. I see that from the error, the particular call happening after the.end()
call is coming from fileC:\Users\Iain\Steambot\EditedBotJS.js
, line 139. The code you provided is much shorter than 139 lines, so I don’t know which one is line 139 to give any pointers? Would you be willing to provide your entire, complete code, or point out which one line line 139?Turns out global variables stay with the same value across different Lambda executions, since they may run in the same container, so set the value of variables inside the exports.handler function and not in the global scope. So now I put const connection = mysql.createConnection({ inside the exports.handler function and I don’t get this MySQL connection errors.
More on the matter: https://forums.aws.amazon.com/thread.jspa?threadID=223230