Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:21:50+00:00 2026-06-13T23:21:50+00:00

Currently using: https://github.com/felixge/node-mysql I have the following code: var connection = mysql.createConnection({ host :

  • 0

Currently using: https://github.com/felixge/node-mysql

I have the following code:

var connection = mysql.createConnection({
    host     : 'localhost',
    user     : 'me',
    password : 'secret',
    database : 'Database1'
});
app.put('/api/upload', function(req, res, next)
{
    connection.connect();
    doMultipleQueries(function(err)
    {
        connection.end();
    });          
};

The put request works perfectly fine, but calling it the second time, I get the following error

events.js:68
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: Cannot enqueue Handshake after invoking quit.
    at Protocol._validateEnqueue (/Users/anon/Desktop/project Web/node_modules/mysql/lib/protocol/Protocol.js:110:16)

Am I supposed to leave the connection open until the server dies?

UPDATE:
When I move the mysql.createConnection into the put request function like so:

var connection = null; 
app.put('/api/upload', function(req, res, next)
{
    connection = mysql.createConnection({
        host     : 'localhost',
        user     : 'me',
        password : 'secret',
        database : 'Database1'
    });
    connection.connect();
    doMultipleQueries(function(err)
    {
        connection.end();
    });          
};

It works fine. Does this mean connection.end() closes what mysql.createConnection created and cannot be reconnected?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:21:50+00:00Added an answer on June 13, 2026 at 11:21 pm

    connection.end() does it job regardless to fatal error. If a fatal error occurs before the COM_QUIT packet can be sent, an err argument will be provided to the callback, but the connection will be terminated regardless of that.

    Also check destroy() method. This will cause an immediate termination of the underlying socket.

    You can add error handler.

    https://github.com/felixge/node-mysql/blob/master/Readme.md#error-handling

    // I am Chuck Norris:
    connection.on('error', function() {});
    

    Once terminated, an existing connection object cannot be re-connected by design.

    Check here. It’s showing connecting back after disconnect.

    https://github.com/felixge/node-mysql/blob/master/Readme.md#server-disconnects

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I am using node-mysql (https://github.com/felixge/node-mysql) and for each result it returns from the
Currently I'm using https://github.com/mranney/node_redis as my node redis client. client.retry_delay is set to 250ms
I'm currently using PagedList (https://github.com/TroyGoode/PagedList/) to manage my paging in an ASP.NET MVC application.
We're currently using Monocle (https://github.com/joseph/Monocle) to build a book-reader application. The scrolling speed of
I have looked at https://github.com/debasishg/sjson and using EGit I was not able to import
I am currently using a memcached-based session store ( https://github.com/mperham/dalli ). From time to
Currently I'm using Mustache templates ( http://mustache.github.com/ ) both on the client and server-side,
Using the sample app for rpx_now gem ( http://github.com/grosser/rpx_now_example ) on localhost:3000, I have
I am trying to set up versioning on my mongomapper model using the https://github.com/Bramanga/mongo_mapper_acts_as_versioned
I'm using https://github.com/markfguerra/GLWallpaperService/ to make an android live wallpaper. I'm trying to load a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.