Cannot connect to replica from tests (zn8)

Stage #zn8 (Python)

Hi folks, I’m trying to replicate commands to the Redis replica. Locally, everything works - I spawn a master, a replica, and I connect to my replica by using sockets, i.e.:

    for location in CLUSTER["replicas"]:
        # Location is a "ip:port" string
        location = location.split(":")
        print(f"replicating to: {location}")
        with socket.create_connection((location[0], location[1])) as s:
            s.sendall(command.encode())

However, when trying to pass the tests, I cannot connect to the replica that the tests create:

[your_program] Exception in thread Thread-1 (handle_conn):
[your_program] Traceback (most recent call last):
[your_program]   File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
[your_program]     self.run()
[your_program]   File "/usr/local/lib/python3.12/threading.py", line 1010, in run
[your_program]     self._target(*self._args, **self._kwargs)
[your_program]   File "/app/app/main.py", line 43, in handle_conn
[your_program]     replication.replicate_command(req)
[your_program]   File "/app/app/replication/__init__.py", line 47, in replicate_command
[your_program]     with socket.create_connection((location[0], location[1])) as s:
[your_program]          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[your_program]   File "/usr/local/lib/python3.12/socket.py", line 853, in create_connection
[your_program]     raise exceptions[0]
[your_program]   File "/usr/local/lib/python3.12/socket.py", line 838, in create_connection
[your_program]     sock.connect(sa)
[your_program] ConnectionRefusedError: [Errno 111] Connection refused

Has anyone encounter anything similar?

Figured it out after reading a number of other confused folks, e.g. [0] [1]. I’m not a fan of the tests forcing architecture decisions, I hope that in the future, the tests can improve and both ways can work (keeping the TCP connection open as well as opening new TCP connection).

[0] Stuck on command replication #ZN8 tests - #9 by rohitpaulk

[1] Replication Stage #ZN8 Help

This is by design :slightly_smiling_face: In the real world, it isn’t guaranteed that a Redis master will be able to initiate an outbound connection to a Redis replica (it might be listening on a private interface).

We could improve the error message for sure though! Will keep an eye out for similar reports.

I think the error message is fairly clear (at least it was to me) - you cannot connect to the replica. What is not clear is that this is intentional.

As I said, I’d prefer if the tests handled connections both ways. If you insist on the test architecture, I’ve already submitted a report suggesting changes to the text. The text mentions this:

Command propagation happens over the replication connection.
This is the same connection that was used for the handshake.

To me, that is not very clear - instead of using passive voice, I’d suggest imperative voice to make it clear that this is a requirement for the tests, and not a piece of information regarding general Redis architecture, e.g.:

Command propagation must happen over the same connection used for the replication handshake. 
The tests do not allow new connection to the replica.

If you added the reasoning for the constraint, that’d be another great piece of information.

Anyways, love the challenges, just spent way too much time on figuring out why this simple thing didn’t work in the tests (while working locally) :slight_smile:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.