Skip to content

Fix 'Address already in use' error with TCP sockets #141

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

Closed
Totktonada opened this issue Feb 18, 2019 · 7 comments · Fixed by #348
Closed

Fix 'Address already in use' error with TCP sockets #141

Totktonada opened this issue Feb 18, 2019 · 7 comments · Fixed by #348
Assignees
Labels
bug Something isn't working

Comments

@Totktonada
Copy link
Member

TcpPortDispatcher was introduced to eliminate the race condition when two workers trying to use the same port: the idea is that each worker use its own ports range. Really these ports could race with client ports (from, say, net.box or replication), which typically don't use bind() and so binds to a random available port (despite any dispatched ranges). So this approach is broken by design.

There is the workaround with use_unix_sockets and use_unix_sockets_iproto options: setting them to True should eliminate the problem. However it is possible that some tests are designed to test tcp connections, so I think we should fix the problem.

The way I see is no-bind / bind to zero port and grep logs for a LISTEN / CONSOLE port (or write it from a script to a predefined location). Remove TcpPortDispatcher and find_port() at all.

Hmm, box.cfg{listen = 0} shows binary: bound to 0.0.0.0:0. Need to elaborate how to get the port.

The discussion had initially arisen in #115.

@Totktonada
Copy link
Member Author

See tarantool/tarantool#4620

@Totktonada
Copy link
Member Author

NB: use_unix_sockets_iproto does not work with core = 'app' test suites.

@Totktonada
Copy link
Member Author

Related: PR #210.

Totktonada added a commit to tarantool/tarantool that referenced this issue May 21, 2020
Support 'use_unix_sockets_iproto' suite.ini option in 'core = app' test
suites. It'll allow to workaround TCP port choosing race (see more in
[1]) by using Unix sockets instead of TCP ones: we did the same for
'core = tarantool' test suites in [2].

[1]: tarantool/test-run#141
[2]: 60f84cb ('test: use unix sockets
     for iproto connections')

Part of #4459.
Totktonada added a commit to tarantool/tarantool that referenced this issue May 21, 2020
Support 'use_unix_sockets_iproto' suite.ini option in 'core = app' test
suites. It'll allow to workaround TCP port choosing race (see more in
[1]) by using Unix sockets instead of TCP ones: we did the same for
'core = tarantool' test suites in [2].

[1]: tarantool/test-run#141
[2]: 60f84cb ('test: use unix sockets
     for iproto connections')

Part of #4459.

(cherry picked from commit b7b9a59)
Totktonada added a commit to tarantool/tarantool that referenced this issue May 21, 2020
Support 'use_unix_sockets_iproto' suite.ini option in 'core = app' test
suites. It'll allow to workaround TCP port choosing race (see more in
[1]) by using Unix sockets instead of TCP ones: we did the same for
'core = tarantool' test suites in [2].

[1]: tarantool/test-run#141
[2]: 60f84cb ('test: use unix sockets
     for iproto connections')

Part of #4459.

(cherry picked from commit b7b9a59)
Totktonada added a commit to tarantool/tarantool that referenced this issue May 21, 2020
Support 'use_unix_sockets_iproto' suite.ini option in 'core = app' test
suites. It'll allow to workaround TCP port choosing race (see more in
[1]) by using Unix sockets instead of TCP ones: we did the same for
'core = tarantool' test suites in [2].

[1]: tarantool/test-run#141
[2]: 60f84cb ('test: use unix sockets
     for iproto connections')

Part of #4459.

(cherry picked from commit b7b9a59)
@kyukhin kyukhin added this to the wishlist milestone Oct 15, 2021
@sergos
Copy link
Contributor

sergos commented Feb 15, 2022

Hmm.. strange, for me it looks like tarantool> box.cfg{listen=0} yields 2022-02-16 01:07:32.744 [19216] main/103/interactive I> tx_binary: bound to [::]:53061 on MacOS and 2022-02-16 01:06:33.753 [10090] main/103/interactive I> tx_binary: bound to 0.0.0.0:36267 on Linux (Ubuntu 18.04)
The problem might be in the difference:

tarantool> box.cfg.listen
---
- 0
...

tarantool> box.info.listen
---
- '[::]:53061'
...

Anyways, letting the Tarantool instance to pick a port by itself looks way more robust, since no delay between assigning a port and binding it.

@Totktonada
Copy link
Member Author

@sergos It is because tarantool/tarantool#4620 was fixed. I filed this issue against tarantool specifically to have a change to use it here, in test-run.

@kyukhin kyukhin added the teamQ label Apr 11, 2022
@kyukhin kyukhin removed this from the wishlist milestone Apr 11, 2022
ylobankov added a commit to ylobankov/tarantool that referenced this issue Jun 6, 2022
To exclude the chance to encounter the tarantool/test-run#141 issue in
replication-py tests let's switch to using unix sockets instead of TCP
ports.

NO_DOC=testing stuff
NO_TEST=testing stuff
NO_CHANGELOG=testing stuff
ylobankov added a commit to ylobankov/tarantool that referenced this issue Jun 7, 2022
To reduce the chance to encounter the tarantool/test-run#141 issue in
tests let's switch to using unix sockets instead of TCP ports where it
is possible.

NO_DOC=testing stuff
NO_TEST=testing stuff
NO_CHANGELOG=testing stuff
ylobankov added a commit to ylobankov/tarantool that referenced this issue Jun 7, 2022
To reduce the chance to encounter the tarantool/test-run#141 issue in
replication-py/swim tests, let's switch to using unix sockets instead
of TCP ports for tarantool console.

NO_DOC=testing stuff
NO_TEST=testing stuff
NO_CHANGELOG=testing stuff
ylobankov added a commit to ylobankov/tarantool that referenced this issue Jun 7, 2022
To reduce the chance to encounter the tarantool/test-run#141 issue in
replication-py/swim tests, let's switch to using unix sockets instead
of TCP ports for tarantool console.

NO_DOC=testing stuff
NO_TEST=testing stuff
NO_CHANGELOG=testing stuff
ylobankov added a commit to tarantool/tarantool that referenced this issue Jun 7, 2022
To reduce the chance to encounter the tarantool/test-run#141 issue in
replication-py/swim tests, let's switch to using unix sockets instead
of TCP ports for tarantool console.

NO_DOC=testing stuff
NO_TEST=testing stuff
NO_CHANGELOG=testing stuff
ylobankov added a commit to tarantool/tarantool that referenced this issue Jun 7, 2022
To reduce the chance to encounter the tarantool/test-run#141 issue in
replication-py/swim tests, let's switch to using unix sockets instead
of TCP ports for tarantool console.

NO_DOC=testing stuff
NO_TEST=testing stuff
NO_CHANGELOG=testing stuff

(cherry picked from commit cb6fc4a)
ylobankov added a commit to tarantool/tarantool that referenced this issue Jun 7, 2022
To reduce the chance to encounter the tarantool/test-run#141 issue in
replication-py tests, let's switch to using unix sockets instead of TCP
ports for tarantool console.

NO_DOC=testing stuff
NO_TEST=testing stuff
NO_CHANGELOG=testing stuff

(cherry picked from commit cb6fc4a)
NickVolynkin added a commit to tarantool/multivac that referenced this issue Aug 30, 2022
Detect specific failure reasons first. If none found in the whole log,
look for generic. This way, specific reasons aren't overshadowed by
generic ones, when those are found first in the logs.

Introduce one specific reason: "Address already in use", subject of
tarantool/test-run#141
NickVolynkin added a commit to tarantool/multivac that referenced this issue Aug 30, 2022
Detect specific failure reasons first. If none found in the whole log,
look for generic. This way, specific reasons aren't overshadowed by
generic ones, when those are found first in the logs.

Introduce one specific reason: "Address already in use", subject of
tarantool/test-run#141
NickVolynkin added a commit to tarantool/multivac that referenced this issue Aug 30, 2022
Detect specific failure reasons first. If none found in the whole log,
look for generic. This way, specific reasons aren't overshadowed by
generic ones, when those are found first in the logs.

Introduce one specific reason: "Address already in use", subject of
tarantool/test-run#141
NickVolynkin added a commit to tarantool/multivac that referenced this issue Aug 30, 2022
Detect specific failure reasons first. If none found in the whole log,
look for generic. This way, specific reasons aren't overshadowed by
generic ones, when those are found first in the logs.

Introduce one specific reason: "Address already in use", subject of
tarantool/test-run#141
mkokryashkin pushed a commit to mkokryashkin/tarantool that referenced this issue Sep 9, 2022
To reduce the chance to encounter the tarantool/test-run#141 issue in
replication-py/swim tests, let's switch to using unix sockets instead
of TCP ports for tarantool console.

NO_DOC=testing stuff
NO_TEST=testing stuff
NO_CHANGELOG=testing stuff
ylobankov added a commit that referenced this issue Sep 12, 2022
This patch makes test-run use only Unix sockets for admin console
connection. The feature to use TCP sockets for it is dropped. Actually,
admin console connection is a purely internal thing of test-run, and we
can use what is more convenient for such a connection. Using only Unix
sockets gives us significant advantages over TCP sockets like connection
speed and eliminating issue with getting a free port for TCP connection.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
This change replaces manual choosing an iproto port for TarantoolServer
by the auto resolving mechanism. In two words, test-run always provides
'127.0.0.1:0' as a value for LISTEN env variable that is used in a lua
file to start a tarantool instance. In this way, the port will be picked
automatically, and we are getting the real value of it via the admin
console by executing `box.info.listen` that is available for tarantool
version >= 2.4.1, and special lua script intended for tarantool version
< 2.4.1.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
This change replaces manual choosing a free iproto port for AppServer
by the auto resolving mechanism. In two words, test-run always provides
'127.0.0.1:0' as a value for LISTEN env variable that is used in a lua
test script. In this way, the iproto port will be picked automatically,
but if the test needs the real value of the port, it has to execute
`box.info.listen` for tarantool version >= 2.4.1, or other lua code for
tarantool version < 2.4.1.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
ylobankov added a commit that referenced this issue Sep 12, 2022
Now this functionality is not needed anymore due to added free port auto
resolving mechanism.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
Now these functions are not needed anymore due to added free port auto
resolving mechanism.

Closes #141
ylobankov added a commit that referenced this issue Sep 12, 2022
This patch makes test-run use only Unix sockets for admin console
connection. The feature to use TCP sockets for it is dropped. Actually,
admin console connection is a purely internal thing of test-run, and we
can use what is more convenient for such a connection. Using only Unix
sockets gives us significant advantages over TCP sockets like connection
speed and eliminating issue with getting a free port for TCP connection.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
This change replaces manual choosing an iproto port for TarantoolServer
by the auto resolving mechanism. In two words, test-run always provides
'127.0.0.1:0' as a value for LISTEN env variable that is used in a lua
file to start a tarantool instance. In this way, the port will be picked
automatically, and we are getting the real value of it via the admin
console by executing `box.info.listen` that is available for tarantool
version >= 2.4.1, and special lua script intended for tarantool version
< 2.4.1.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
This change replaces manual choosing a free iproto port for AppServer
by the auto resolving mechanism. In two words, test-run always provides
'127.0.0.1:0' as a value for LISTEN env variable that is used in a lua
test script. In this way, the iproto port will be picked automatically,
but if the test needs the real value of the port, it has to execute
`box.info.listen` for tarantool version >= 2.4.1, or other lua code for
tarantool version < 2.4.1.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
ylobankov added a commit that referenced this issue Sep 12, 2022
Now this functionality is not needed anymore due to added free port auto
resolving mechanism.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
Now these functions are not needed anymore due to added free port auto
resolving mechanism.

Closes #141
ylobankov added a commit that referenced this issue Sep 12, 2022
This patch makes test-run use only Unix sockets for admin console
connection. The feature to use TCP sockets for it is dropped. Actually,
admin console connection is a purely internal thing of test-run, and we
can use what is more convenient for such a connection. Using only Unix
sockets gives us significant advantages over TCP sockets like connection
speed and eliminating issue with getting a free port for TCP connection.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
This change replaces manual choosing an iproto port for TarantoolServer
by the auto resolving mechanism. In two words, test-run always provides
'127.0.0.1:0' as a value for LISTEN env variable that is used in a lua
file to start a tarantool instance. In this way, the port will be picked
automatically, and we are getting the real value of it via the admin
console by executing `box.info.listen` that is available for tarantool
version >= 2.4.1, and special lua script intended for tarantool version
< 2.4.1.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
This change replaces manual choosing a free iproto port for AppServer
by the auto resolving mechanism. In two words, test-run always provides
'127.0.0.1:0' as a value for LISTEN env variable that is used in a lua
test script. In this way, the iproto port will be picked automatically,
but if the test needs the real value of the port, it has to execute
`box.info.listen` for tarantool version >= 2.4.1, or other lua code for
tarantool version < 2.4.1.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
ylobankov added a commit that referenced this issue Sep 12, 2022
Now this functionality is not needed anymore due to added free port auto
resolving mechanism.

Part of #141
ylobankov added a commit that referenced this issue Sep 12, 2022
Now these functions are not needed anymore due to added free port auto
resolving mechanism.

Closes #141
ylobankov added a commit that referenced this issue Sep 15, 2022
This patch improves getting the iproto port for tarantool < 2.4.1.
The previous revision of the lua script might give unstable result
(more than 1 port) and test-run failed. Now it is fixed.

Follows up #141
ylobankov added a commit that referenced this issue Sep 15, 2022
This patch improves getting the iproto port for tarantool < 2.4.1.
The previous revision of the lua script might give unstable result
(more than 1 port) and test-run failed. Now it is fixed.

Follows up #141
@NickZay
Copy link

NickZay commented Mar 13, 2024

I have some problems with ports when I use luatest with tarantool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants