[SERVER-18600] resmoke.py should avoid assigning duplicate ports to mongod processes Created: 21/May/15  Updated: 19/Sep/15  Resolved: 21/May/15

Status: Closed
Project: Core Server
Component/s: Testing Infrastructure
Affects Version/s: 3.1.3
Fix Version/s: 3.1.4

Type: Bug Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Max Hirschhorn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Quint Iteration 4
Participants:
Linked BF Score: 0

 Description   

For the mongod processes that resmoke.py creates, an unused port is requested from the OS

self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.__socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.__socket.bind(("0.0.0.0", 0))

by creating a socket, closing it, and then handing the port number that was received from the OS to the mongod command line. Note that this is racy in a way that is not easy to fix.

However, another issue arises from the way resmoke.py starts multiple mongod processes when the --jobs=N flag is specified. The MongoDFixture.setup() method starts the process, but returns before attempting to establish a connection to the mongod. Instead, resmoke.py starts a mongod processes for each job without waiting to see if a connection can be established before starting the next. After all of the mongod processes are started, MongoDFixture.await_ready() is called on each to ensure a connection can be established. This was done so that the initialization of mongod processes can happen concurrently, which decreases the overall execution time.

The following sequence of events describes the problem:

Job 1 gets port 42000
(Job 1 closes its socket)
Job 1 starts a mongod process on port 42000
Job 2 gets port 42000
(Job 2 closes its socket)
The mongod process of Job 1 calls bind() on port 42000 (ok)
Job 2 starts a mongod process on port 42000
The mongod process of Job 2 calls bind() on port 42000 (fails because the address is already in use)

The proposal is to have the UnusedPort class keep track of the set of ports that have been acquired by each instance and to request another port from the OS if a duplicate is received.



 Comments   
Comment by Githook User [ 21/May/15 ]

Author:

{u'username': u'visemet', u'name': u'Max Hirschhorn', u'email': u'max.hirschhorn@mongodb.com'}

Message: SERVER-18600 Avoid giving the same port to multiple processes.
Branch: master
https://github.com/mongodb/mongo/commit/cbad13858229d7dafb41d1e6bf3ba05aa1f29503

Generated at Thu Feb 08 03:48:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.