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.

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