Skip to content

RWorkerProcess.Start fails with WARNING Error in findPort(port) : Port must be an integer in the range of 1024 to 49151 #27

@jjrob

Description

@jjrob

When starting RWorkerProcess, these messages may appear:

2025-03-05 13:36:18.200 WARNING Error in findPort(port) :
2025-03-05 13:36:18.200 WARNING   Port must be an integer in the range 1024 to 49151 (inclusive).
2025-03-05 13:36:18.202 WARNING Calls: %>% -> pr_run -> <Anonymous> -> findPort
2025-03-05 13:36:18.202 WARNING Execution halted

followed by this exception:

RuntimeError: 15.0 seconds have elapsed after starting MGET's R worker process without the process indicating it is ready. Please check preceding log messages to determine if there is a problem with R. If not, consider increasing the Startup Timeout to allow R more time to initialize.

The problem is that the Python code we're using to obtain a port:

                if self._RequestedPort is None:
                    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
                        s.bind(('127.0.0.1', 0))
                        self._Port = int(s.getsockname()[1])

Can apparently return ports beyond this 49151 limit. We then ask R to listen on one of those too-high ports and it fails. The solution is probably to limit generation of port numbers to below that limit. Something like this:

                if self._RequestedPort is None:
                    for i in range(1000):
                        port = random.randint(1024, 49151)
                        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
                            try:
                                s.bind(('127.0.0.1', port))
                            except OSError:
                                port = None
                                continue
                            else:
                                break
                    if port is None:
                        raise RuntimeError(_('Could not find an available TCP port for Python/R communication. Please try this operation again. If it continues to fail, please contact the MGET development team for assistance.'))
                    self._Port = port

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions