node-mysql2
node-mysql2 copied to clipboard
Question on pooling over socks
Hi, Trying to make a pooled connection to mysql server on a remote host over socks5 proxy using socks nodejs package. I use options.stream as a factory function with already prepared net.socket stream:
const SocksClient = require('socks').SocksClient;
try {
const info = await SocksClient.createConnection(options);
console.log(info.socket);
// <Socket ...> (this is a raw net.Socket that is established to the destination host through the given proxy server)
const mysqlClient = require("mysql2");
const conn = mysqlClient.createPool({
user: "some-user-name",
password: "some-password",
ssl: services.mysql.ssl,
stream: function (options) {
return info.socket;
}
});
// some requests with `conn.query` or `conn.getConnection`
} catch (err) {
console.log(err); // Handle errors
next(err);
}
So, in this code each connection in the pool would use the same socks5 stream. The test works fine, however, the question is: is it a correct implementation or should I create a separate stream for each pooled connection?
Also, in some comments here I saw that the stream factory function was supposed to have a callback and now it does not. Is this intentional?
Thank you.