Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect to mysql after upgrading to 2.3.3 #136

Closed
rrosenblum opened this issue May 8, 2019 · 5 comments
Closed

Unable to connect to mysql after upgrading to 2.3.3 #136

rrosenblum opened this issue May 8, 2019 · 5 comments

Comments

@rrosenblum
Copy link

rrosenblum commented May 8, 2019

After upgrading from version 2.2.0 to 2.3.3, I am unable to connect to mysql. I believe this is related to #98. There isn't much of an actual error being produced that I can see. The lambda just winds up timing out without ever actually connecting to mysql. I have tried increasing the timeout. I think this might be related to #98.

I have tried 2 different ways to capture mysql.

const AWSXRay = require('aws-xray-sdk-core');    
const captureMySQL = require('aws-xray-sdk-mysql');    
const mysql = captureMySQL(require('mysql'));    
                                         
const pool = mysql.createPool({    
  host: process.env.DB_PRIMARY_ENDPOINT,    
  database: process.env.DB_NAME,    
  port: process.env.DB_PORT,    
  user: process.env.DB_USERNAME,    
  password: process.env.DB_PASSWORD    
});

module.exports.handler = async (event) => {
  pool.query
}
const mysql = require('aws-xray-sdk').captureMySQL(require('mysql'));    
    
const pool = mysql.createPool({    
  host: process.env.DB_PRIMARY_ENDPOINT,    
  database: process.env.DB_NAME,    
  port: process.env.DB_PORT,    
  user: process.env.DB_USERNAME,    
  password: process.env.DB_PASSWORD    
});

module.exports.handler = async (event) => {
  pool.query
}
@awssandra
Copy link
Contributor

Hi rrosenblum,

Sorry for the issues. We'll do some testing on our end to see what the issue is. I think it's a fair call that the mysql2 changes may have broken the mysql patch functionality.

@M-TGH
Copy link
Contributor

M-TGH commented May 8, 2019

Hey,

Thanks for the report. My apologies for any inconveniences. I didn't have too much time so far to look into it, but I was able to reproduce it. For now it should be alright to (temporarily) remove the parts that patch a Pool it's getConnection function.

So far it looked like it's somewhere down that line that something was hitting a snag, maybe because the MySQL package internally uses getConnection on the Pool when using Pool.query. Unfortunately I couldn't yet figure out the full problem, but I'll try looking into it more as soon as I have the time.

Suppose it might be interesting to see if this can be replicated with a test which stubs/simulates a Pool's query function.

Let me know if I can be of any more help.

@M-TGH
Copy link
Contributor

M-TGH commented May 9, 2019

After looking into it further, Pool.query creates a Query instance and a connection and then calls the connection.query function with only the Query instance as argument. This falls into this case, from further up in query: https://github.com/mysqljs/mysql/blob/99d6f78ba00f926de162dbef42865029b6e8ec39/lib/Connection.js#L26

It's currently going into this if statement:

if (argsObj[0] instanceof Object) {

Which then splits up the Query instance that was passed through and currently makes it so that a new one is created by calling Connection.query with its sql and values, thereby losing the original Query instances EventEmitter.

@yvele
Copy link

yvele commented May 20, 2019

Same problem with aws-xray-sdk-mysql version >=2.3.0

Temporary workaround, downgrade aws-xray-sdk-mysql:

"dependencies": {
    "aws-xray-sdk-core": "~2.3.3",
    "aws-xray-sdk-mysql": "2.2.0"
}

@willarmiros
Copy link
Contributor

Closing since it was fixed in PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants