You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The resolveArguments function to determine the arguments of a mysql connection.query or connection.execute incorrectly assumes the callback position for the mysql2 driver is the second argument.
{'0': {sql: '\n'+' INSERT INTO session (id, token_exp, known_ips)\n'+' VALUES\n'+' (?, ?, ? )\n'+' ON DUPLICATE KEY UPDATE\n'+' id = ?, token_exp = ?, known_ips = ?\n'+' '},'1': ['aS9e9ng4AKqb6sKU3h_wN',1615328288,'[]','aS9e9ng4AKqb6sKU3h_wN',1615328288,'[]'],'2': [Function(anonymous)]}
Note that the value of arguments[0] is an Object. This means that arguments test in resolveArguments flows onto the wrong branch when testing using if (argsObj[0] instanceof Object) { (from aws-xray-sdk-node/packages/mysql/lib/mysql_p.js#L143)
I only noticed this issue when using knex and async/await, however I assume other newer ORMs or query builders are using the mysql2 driver in the same way.
Suggested Fix
Account for this possibility with additional tests in resolveArguments as below:
functioncaptureOperation(name){returnfunction(){varargs=resolveArguments(arguments);
...
if(args.callback){varcb=args.callback;// incorrectly set to arguments[1] which are `values`if(AWSXRay.isAutomaticMode()){args.callback=functionautoContext(err,data){varsession=AWSXRay.getNamespace();session.run(function(){AWSXRay.setSegment(subsegment);cb(err,data);// FAILS HERE because 'cb' is not a function (is the array fo values)});
...
};}
Fixes issue with mysql2 query where 1st argument is of type Object, 2nd argument is an array of values for binding to sql query, and 3rd argument is callback.
fixesaws#380
Issue
The
resolveArguments
function to determine the arguments of a mysqlconnection.query
orconnection.execute
incorrectly assumes the callback position for themysql2
driver is the second argument.The arguments of
connection.query
for themysql2
driver are: (from mysql2/packages/mysql/lib/mysql_p.js#L146)By inspecting the contents of
arguments
in the XRay mysql wrapper when doing a complexINSERT
(from aws-xray-sdk-node/packages/mysql/lib/mysql_p.js#L161) using the following code... the results are:
contents of
arguments
Note that the value of
arguments[0]
is anObject
. This means thatarguments
test inresolveArguments
flows onto the wrong branch when testing usingif (argsObj[0] instanceof Object) {
(from aws-xray-sdk-node/packages/mysql/lib/mysql_p.js#L143)I only noticed this issue when using
knex
and async/await, however I assume other newer ORMs or query builders are using themysql2
driver in the same way.Suggested Fix
Account for this possibility with additional tests in
resolveArguments
as below:Implications for not implementing change
mysql2
based queries will fail on the following line becausecb is not a function
(from aws-xray-sdk-node/packages/mysql/lib/mysql_p.js#L188):Environment
Tested with:
[email protected]
[email protected]
[email protected]
The text was updated successfully, but these errors were encountered: