"Oops, it seems like there are an excessive number of connections in Express MySQL causing

While programming in Angular and creating an API server in Express, I encountered a minor issue after spending hours coding and making requests to the API. The problem arises when the maximum number of requests is reached, resulting in an error.

Everything works smoothly until a certain point where the error occurs and causes the database to disconnect while the frontend in Angular remains functional.

After some time, the server throws this error:

(node:10356) UnhandledPromiseRejectionWarning: Error: ER_CON_COUNT_ERROR: Too many connections
   // Error details...

The function to connect to my database looks like this:

import { createPool } from "promise-mysql";
import keys from "./keys";

export async function connect(){
    const connection = createPool(keys.database);    
    return connection;
}

And my index file includes the following configurations:

import express, { Application } from "express";
import morgan from 'morgan';
import cors from 'cors';

// Other imports...

class Server {
    public app: Application;

    constructor(){
        this.app = express();
        this.config();
        this.routes();
    }
// Configuration settings
    config(): void{
       // Configurations...
    }
// Routes setup
    routes(): void {
       // Route definitions...
    }
// Start the server
    start(): void{
       // Initiate server...
    }
}

const server = new Server();
server.start();

If someone has experience with this issue and can provide guidance on how to solve it, please reach out as this problem tends to arise only after extended periods of programming.

Answer №1

The default value of max_connect_errors in MySQL is set to 100. However, when using connection pools, a series of sporadic errors can accumulate quickly and reach up to 64, resulting in user experience issues.

To address this issue, consider implementing the following solutions:

Solution 1: Disable connection pooling and opt for simple per-connection setups.

Solution 2: Increase the max_connect_errors parameter to its maximum as specified in the documentation.

Solution 3: Investigate and analyze the specific errors occurring to determine if they are caused by programming errors or temporary network connectivity issues.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

BOOTSTRAP: changing the layout of panels in various sizes for mobile devices

I'm struggling with how to reorganize my panels on mobile devices. Each panel has a different size. Please refer to the attached screenshot for the page layout on large screens (col-lg): EDIT: The layout on large screens looks fine, as I prefer not t ...

What is the best way to access a database connection throughout an entire node.js application?

In my application's app.js file, I establish a connection to mongodb using the monk module. var express = require('express'); var cookieParser = require('cookie-parser'); var bodyParser = require('body-parser'); var mong ...

How can we assign priority to the child element for detection by the "mouseover" event in jQuery?

Can you help me figure out how to make the "mouseover" event prioritize detecting the child element over its parent? This is the jQuery code I've been using: <script> $(function() { $("li").mouseover(function(event){ $('#log&a ...

AngularJS is not triggering the $watch function

I'm facing an issue with the $scope.$watch function, as it's not being triggered when expected. In my HTML document, I have a paginator using bootstrap UI: <pagination total-items="paginatorTotalItems" items-per-page="paginatorItemsPerPage" ...

Tips for utilizing the getJson method to pass a variable to a PHP file

I need help with my JavaScript code, as I am trying to pass a datastring containing the value "no" to data.php using getJson in order to receive JSON as a response. However, my JavaScript code is not functioning correctly. Below is the code that I have: J ...

Error Message: Unexpected Type Error with axios in Vue 3

Trying to implement axios in my Vue3 project for fetching APIs. Here is the code snippet from my component: export default { name: "Step2", data() { return { loading: true; }; }, mounted() { this.loading = false; }, ...

Browsing through a jQuery JSON object in Chrome reveals a dynamic reshuffling of its order

Jquery + rails 4 Within the json_data instance, there is data with key-value pairs. The key is an integer ID and the value is an object containing data. However, when attempting to iterate over this data using the jQuery $.each function, the results are s ...

Seeking assistance with downloading a collection of images as a zipped file using AngularJS

My code was previously working with jszip 2x but now I'm getting an error stating "This method has been removed in JSZip 3.0, please check the upgrade guide.". Even after following the upgrade guide, my code is still not functioning properly. I need a ...

In order to add value, it is necessary to insert it into the text box in HTML without using the "on

example <input type="text" id="txt1" onChange="calculateTotal();" /> <input type="text" id="txt2" onChange="calculateTotal();" /> <input type="text" id="txt3" onChange="updateValue();" readonly/> <input type="text" id="txt4" onChange= ...

The import component path in Angular 4/TypeScript is not being recognized, even though it appears to be valid and functional

I'm currently working on building a router component using Angular and TypeScript. Check out my project structure below: https://i.stack.imgur.com/h2Y9k.png Let's delve into the landingPageComponent. From the image, you can see that the path ...

Experimenting with views in the express framework

I need help determining the best method for testing my Jade views that include some logic. For instance, on the homepage, I want to show a button linking to the main console and an option to log out if a cookie is set, but display a login option if no cook ...

Disable reloading when submitting and reset input fields after submission

I am working on developing a website where users can post things and comments without the need to refresh the page. I have encountered some issues while implementing this feature and need some assistance with it. My goal is to allow users to submit comment ...

Retrieve the node-postgres result and store it in a separate object beyond the callback function

Currently, I am in the process of converting a data profiling script originally written in Python to JavaScript while following the Wes Bos beginner Javascript Course. This script is designed to take database connection details and a specified target tabl ...

Is it possible to have a Socket.io session without using express.js?

Looking to establish session management through websockets using node.js and socket.io, without relying on cookies and bypassing express.js. This is important as there may be clients that do not run in a traditional browser environment. Has anyone succes ...

How can one properly iterate through an HTML Collection in JavaScript?

I need help with creating a slider using JavaScript. The code I have written below calculates the widths of the slides, but it's throwing an error in the console. Can someone advise on how to properly loop through and assign width to these elements? ...

Node generates parallel instances of mysql connections and fails to terminate them afterwards

I am currently working on a project that involves using loopback, node, and MySQL to make parallel database calls. Even though there is already a persistent connection established between node and MySQL, when these parallel calls are executed, new connecti ...

Error in Continuous Integration for Angular 4: Unable to access property 'x' of an undefined variable

i am trying to display some data on the form but encountering an error: TypeError: Cannot read property 'title' of undefined below is my component code : book:Book; getBook(){ var id = this.route.snapshot.params['id']; ...

Iterating over a nested document containing subarrays and rendering them on an EJS template

My aim here is to iterate through an embedded document and display comments for the posts with matching IDs. This is my Schema structure on the node.js server: var postSchema = new mongoose.Schema({ name: String, post: String, comment: [ ...

Is there a way to prevent undefined properties when using .each in jQuery with a JSON object?

I am trying to populate the values of <inputs> on a webpage using data from a JSON object. http://codepen.io/jimmykup/pen/exAip?editors=101 To begin, I create a JSON object with two values - one for name and one for url. var jsonObj = []; var nam ...

The quickForm Meteor encountered an exception in the template helper: There was an error stating that Recipes is not within the window

I'm having trouble getting the app to work on Meteor. The quickform is not connecting to my Collection. "Error: Recipes is not in the window scope" Can anyone offer assistance with this issue? Below is my quickform code: <template name="NewRe ...