sidorares / sidorares/node-mysql2

Error: This socket has been ended by the other party mysql

Open
#990 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

I made simple rest api with node js and when I try to reach remote mysql database on my machine it works. But, when i deploy my app to pivotal web service and make simple api call I am getting no response. With Quota Guard I provided two static ip addresses, so app is allowed to access mysql db.
Here is a log. Also, I am very new to node js, so I dont know what possibly could go wrong.

2019-07-31T14:49:37.708Z [APP/PROC/WEB/0] [OUT] { Error: This socket has been ended by the other party
2019-07-31T14:49:37.708Z [APP/PROC/WEB/0] [OUT] at Socket.writeAfterFIN [as write] (net.js:395:12)
2019-07-31T14:49:37.708Z [APP/PROC/WEB/0] [OUT] at SocksConnection._write (/home/vcap/app/node_modules/socksjs/socks.js:72:24)
2019-07-31T14:49:37.708Z [APP/PROC/WEB/0] [OUT] at doWrite (_stream_writable.js:415:12)
2019-07-31T14:49:37.708Z [APP/PROC/WEB/0] [OUT] at writeOrBuffer (_stream_writable.js:399:5)
2019-07-31T14:49:37.708Z [APP/PROC/WEB/0] [OUT] at SocksConnection.Writable.write (_stream_writable.js:299:11)
2019-07-31T14:49:37.708Z [APP/PROC/WEB/0] [OUT] at PoolConnection.write (/home/vcap/app/node_modules/mysql2/lib/connection.js:221:17)
2019-07-31T14:49:37.708Z [APP/PROC/WEB/0] [OUT] at PoolConnection.writePacket (/home/vcap/app/node_modules/mysql2/lib/connection.js:279:12)
2019-07-31T14:49:37.708Z [APP/PROC/WEB/0] [OUT] at ClientHandshake.sendCredentials (/home/vcap/app/node_modules/mysql2/lib/commands/client_handshake.js:63:16)
2019-07-31T14:49:37.708Z [APP/PROC/WEB/0] [OUT] at ClientHandshake.handshakeInit (/home/vcap/app/node_modules/mysql2/lib/commands/client_handshake.js:136:12)
2019-07-31T14:49:37.708Z [APP/PROC/WEB/0] [OUT] at ClientHandshake.execute (/home/vcap/app/node_modules/mysql2/lib/commands/command.js:39:22) code: 'EPIPE', fatal: true }
2019-07-31T16:50:05.656+02:00 [APP/PROC/WEB/0] [OUT] { Error: connect ETIMEDOUT
2019-07-31T16:50:05.656+02:00 [APP/PROC/WEB/0] [OUT] at tryOnTimeout (timers.js:300:5)
2019-07-31T16:50:05.656+02:00 [APP/PROC/WEB/0] [OUT] at PoolConnection._handleTimeoutError (/home/vcap/app/node_modules/mysql2/lib/connection.js:171:17)
2019-07-31T16:50:05.656+02:00 [APP/PROC/WEB/0] [OUT] at ontimeout (timers.js:436:11)
2019-07-31T16:50:05.656+02:00 [APP/PROC/WEB/0] [OUT] at listOnTimeout (timers.js:263:5)
2019-07-31T16:50:05.656+02:00 [APP/PROC/WEB/0] [OUT] at Timer.processTimers (timers.js:223:10)
2019-07-31T16:50:05.656+02:00 [APP/PROC/WEB/0] [OUT] errorno: 'ETIMEDOUT',
2019-07-31T16:50:05.656+02:00 [APP/PROC/WEB/0] [OUT] code: 'ETIMEDOUT',
2019-07-31T16:50:05.656+02:00 [APP/PROC/WEB/0] [OUT] syscall: 'connect',
2019-07-31T16:50:05.656+02:00 [APP/PROC/WEB/0] [OUT] fatal: true }

`const express = require('express');
const db = require('../db');

const mainNewsRouter = express.Router();

mainNewsRouter.get('/', async (req, res, next) => {
    try {
      let result = await db.getMainNews();
      console.log(res.json(result));
      res.json(result);
    } catch(e) {
      console.log(e);
    }
});

module.exports = mainNewsRouter;

//DbHandler.js

var mysql = require('mysql2');
const url = require('url');
var SocksConnection = require('socksjs');

var remote_options = {
    host:'xxx',
    port: 3306
};

var proxy = url.parse('http://xxx:xxx@us-east-static-06.quotaguard.com:xxx');
var auth = proxy.auth;
var username = auth.split(":")[0];
var pass = auth.split(":")[1];

var sock_options = {
host: proxy.hostname,
port: 1080,
user: username,
pass: pass
};

var sockConn = new SocksConnection(remote_options, sock_options);
var dbConnection = mysql.createPool({
    connectionLimit: 10,
    user: 'xxx',
    database: 'xxx',
    password: 'xxx',
    stream: sockConn
});


getMainNews = () => {

  return new Promise((resolve, reject) => {
      dbConnection.query('SELECT ... * from ...;',
     (err, results) => {
        if (err) {
          return reject(err);
        };

//          sockConn.dispose();
          return resolve(results);
      });
  });

  dbConnection.end();
};

`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Express route and the DbHandler.js connection setup, especially the mysql2 pool and SocksConnection stream, and review the EPIPE and ETIMEDOUT logs together. Check how the remote MySQL connection behaves through Quota Guard on the deployed service; done means identifying a confirmed connection cause and documenting a reproducible fix or required configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, mysql, node.js
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.