Connection with pool never closes

See original GitHub issue

I am using AWS Lambda and API Gateway together to build a REST API for the web application at my job. I noticed that the connections to the MySQL server never get closed, or am I wrong based on the info below?

Single AWS Lambda function

var Sequelize = require('sequelize'),
    seqlz = new Sequelize('db', 'user', 'password', {
        host: 'mydbdomain.com',
        port: '3306',
        dialect: 'mysql',
        timezone: 'UTC-05:00',
        pool: {
            max: 1,
            min: 0,
            idle: 5000
        }
    }),
    Promotion = seqlz.define('promotion', {
        tournamentId: {
            type: Sequelize.BIGINT(20),
            primaryKey: true
        },
        iconFilePath: Sequelize.STRING,
        name: Sequelize.STRING(75),
        eventStartDate: Sequelize.DATE,
        eventEndDate: Sequelize.DATE
    }, {
        timestamps: false,
        tableName: 'Tournament'
    }),
    Advertiser = seqlz.define('advertiser', {
        advertiserId: {
            type: Sequelize.BIGINT(20),
            primaryKey: true
        },
        name: Sequelize.STRING(75),
    }, {
        timestamps: false,
        tableName: 'Advertiser'
    }),
    Game = seqlz.define('game', {
        gameId: {
            type: Sequelize.BIGINT(20),
            primaryKey: true
        },
        name: Sequelize.STRING(75)
    }, {
        timestamps: false,
        tableName: 'Game'
    }),
    GamePlayLog = seqlz.define('gamePlayLog', {
        gamePlayLogId: {
            type: Sequelize.BIGINT(20),
            primaryKey: true
        },
        createdDate: Sequelize.DATE
    }, {
        timestamps: false,
        tableName: 'GamePlayLog'
    });

Promotion.belongsTo(Advertiser, {foreignKey: 'advertiserId'});
Promotion.belongsTo(Game, {foreignKey: 'gameId'});
Promotion.hasMany(GamePlayLog, {foreignKey: 'tournamentId'});

exports.handler = function(event, context) {
    Promotion.findAll({
        attributes: [
            'tournamentId',
            'name',
            'eventStartDate',
            'eventEndDate'
        ],
        where: {status: 3},
        include: [
            {
                model: Advertiser,
                attributes: ['name']
            },
            {
                model: Game,
                attributes: ['name']
            },
            {
                model: GamePlayLog,
                attributes: ['createdDate']
            }
        ]
    }).then(function(promos) {
        context.done(null, promos);
    });
};

I’d assume the connection would automatically close after 5 seconds of no use, but it’s not not unless I’m misinterpreting what I’m seeing on MySQL Workbench. I tried using sequelize.close() before context.done() (with and w/o the pool) but would get an error at random times: Unhandled rejection Error: ConnectionManager.getConnection was called after the connection manager was closed!

Here’s an image of my MySQL Workbench. At the time of this screenshot, the connections had been hanging for over 500 seconds if I’m not mistaken. Way more than 5 seconds lol. They are the ones that begin with ec2.

http://oi67.tinypic.com/314qkqe.jpg

Any help is appreciated!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
catamphetaminecommented, Aug 27, 2020

^^^ The guy looks credible

1reaction
marcogrcrcommented, Aug 26, 2020

For people experiencing issues in AWS Lambda, I have created a pull request that documents how to properly configure sequelize for Lambda. Hopefully you’ll be able to see it in https://sequelize.org/master/manual/aws-lambda.html once it gets merged. In the meantime, please check #12642 out and provide feedback if you find any inaccuracies or space for improvement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection pool is never closed with node-oracledb and nodejs
The connection to the database is succesful. The problem is that when I want to terminate the application and close the connection pool,...
Read more >
All connections from pool are suddenly closed or never released
After some days of normal use, the driver suddenly closes all the connections of the pool (there is no driver.
Read more >
Connection Pool Leaving Connections Open — oracle-tech
The problem is that connections aren't being closed and the those connections are remaining active on the database.
Read more >
Help! "connection is closed by the pool" : r/gpumining - Reddit
I keep getting "connection is closed by the pool" when attempting to connect. My config - What did I screw up? setx GPU_FORCE_64BIT_PTR...
Read more >
How do you work with closing pools/connections?
Yes, you'd "close" (or release) the Connection - the Pool maintains a list of Connections for your application to use (FIFO queuing the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found