Skip to content

Conversation

@Priyank-Gaur
Copy link
Contributor

This PR updates the “Connecting using custom stream” documentation.

The old example used a callback-style:
stream: function (cb) { ... }

This pattern no longer works in current versions of mysql2 and results in the runtime error:
TypeError: cb is not a function

What changed

Replaced the outdated callback-based SOCKS5 example.
Added a modern example where stream returns a Duplex stream or a Promise that resolves to one.
Added a short note explaining that the callback-style API is no longer supported.

Why this change

The existing docs mislead users into using a deprecated pattern that fails on current mysql2 versions.
The updated version shows the correct API and prevents confusion/errors for anyone connecting over SOCKS5 or other custom transport streams.

Related Issue
Fixes #3655

@codecov

This comment was marked as off-topic.

@wellwelwel wellwelwel merged commit 27d63c0 into sidorares:master Nov 17, 2025
101 checks passed
@wellwelwel
Copy link
Collaborator

Thanks, @Priyank-Gaur! ✨

@siddharthvp
Copy link

What versions of mysql2 and socks is this tested with?

With the latest ones (mysql2 3.15.3, socks 2.8.7):

Firstly, socks createConnection requires command to be passed. Without that it gives:

SocksClientError: An invalid SOCKS command was provided. Valid options are connect, bind, and associate.

If we set command to any of those 3 values, the code gives:

    this.stream.on('error', this._handleNetworkError.bind(this));
                ^
TypeError: this.stream.on is not a function

when getting a connection from the pool.

@Priyank-Gaur
Copy link
Contributor Author

What versions of mysql2 and socks is this tested with?

With the latest ones (mysql2 3.15.3, socks 2.8.7):

Firstly, socks createConnection requires command to be passed. Without that it gives:

SocksClientError: An invalid SOCKS command was provided. Valid options are connect, bind, and associate.

If we set command to any of those 3 values, the code gives:

    this.stream.on('error', this._handleNetworkError.bind(this));
                ^
TypeError: this.stream.on is not a function

when getting a connection from the pool.

Thanks for checking this!

My PR focused on updating the old callback-style example to the modern stream-returning API since the previous example no longer worked with mysql2.

It looks like the SOCKS library (socks package) now requires an additional command field and may behave differently in the latest versions.

If needed, I can open a follow-up PR or If you want you can open a PR to update the example with a working configuration for the latest socks version.

@siddharthvp
Copy link

As I said in #3655, there is no working configuration I can come up with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pooling over a socks5 proxy does not work

3 participants