Replication Stage (#BW1) address already in use error

I’m stuck on Replication Stage #3. I am using C++.

In previous stages, I have not encountered this error as I suppose the SO_REUSEADDR set to 1 solves the problem. But in this case, I get errors. See logs below:

Here are my logs:

[replication-2] client: Received bytes: "$11\r\nrole:master\r\n"
[replication-2] client: Received RESP value: "role:master"
[replication-2] Received "role:master"
[replication-2] Found role:master in response.
[replication-2] Test passed.
[replication-2] Terminating program
[replication-2] Program terminated successfully

[replication-3] Running tests for Replication > Stage #3: The INFO command on a replica
[replication-3] This failure most likely means that your server didn't use the SO_REUSEADDR socket option while starting the server in the previous stage. SO_REUSEADDR is required to reuse previous sockets which were bound on the same address. Try setting the SO_REUSEADDR flag when creating your TCP server.
[replication-3] Error starting TCP server: listen tcp :6379: bind: address already in use
[replication-3] Test failed

@joshting Ah, yeah this definitely isn’t expected. Mind sharing a link to your code, or a snippet around where you’re using SO_REUSEADDR?

@joshting we were able to locate your repository, looks like it was created a while ago, before we fixed a bug. Here’s the fix if it helps: CC-1030: Replace usage of SO_REUSEPORT with SO_REUSEADDR. by ryan-gang · Pull Request #139 · codecrafters-io/build-your-own-redis · GitHub

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

Note: I’ve updated the title of this post to include the stage ID (#BW1). You can learn about the stages rename here: Upcoming change: Stages overhaul