Skip to content

Commit f6e63ef

Browse files
committed
Merge pull request #7647
d7b74a4 Tests: Fix test node_server.bind_same_p2p_port from randomly crashing (mj-xmr)
2 parents 298208d + d7b74a4 commit f6e63ef

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/unit_tests/node_server.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,18 @@ TEST(node_server, bind_same_p2p_port)
294294
boost::program_options::variables_map vm;
295295
boost::program_options::store(boost::program_options::parse_command_line(1, argv, desc_options), vm);
296296

297+
/*
298+
Reason for choosing '127.0.0.2' as the IP:
299+
300+
A TCP local socket address that has been bound is unavailable for some time after closing, unless the SO_REUSEADDR flag has been set.
301+
That's why connections with automatically assigned source port 48080/58080 from previous test blocks the next to bind acceptor
302+
so solution is to either set reuse_addr option for each socket in all tests
303+
or use ip different from localhost for acceptors in order to not interfere with automatically assigned source endpoints
304+
305+
Relevant part about REUSEADDR from man:
306+
https://www.man7.org/linux/man-pages/man7/ip.7.html
307+
*/
308+
vm.find(nodetool::arg_p2p_bind_ip.name)->second = boost::program_options::variable_value(std::string("127.0.0.2"), false);
297309
vm.find(nodetool::arg_p2p_bind_port.name)->second = boost::program_options::variable_value(std::string(port), false);
298310

299311
boost::program_options::notify(vm);

0 commit comments

Comments
 (0)