Skip to content

ignore slaveof no one in redis.conf#7842

Merged
oranagra merged 6 commits intoredis:unstablefrom
CaoZB:unstable
Sep 27, 2020
Merged

ignore slaveof no one in redis.conf#7842
oranagra merged 6 commits intoredis:unstablefrom
CaoZB:unstable

Conversation

@CaoZB
Copy link
Contributor

@CaoZB CaoZB commented Sep 24, 2020

I configure slaveof no one in redis.conf by accident,and redis tried to connect to no:0.I think that's not what i expected.

@oranagra
Copy link
Member

no one ever said that the config file supports this, but you're right that someone may try to do that by mistake.
i think the right solution is to check that that atoi failed, and goto loaderr (redis should fail to start).
what do you think?

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 25, 2020

OK,as long as it can avoid redis trying to connect to no:0.😃

@oranagra
Copy link
Member

So do you wanna do that (change the PR)?

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 25, 2020

Do you mean submitting another PR or directly changing the current PR?(sorry,i'm not experienced in submitting pull requests😞)

@oranagra
Copy link
Member

You can push another commit into the same branch, or amend the commit and push - f

@oranagra
Copy link
Member

Looks like CONFIG REWRITE is generating such a config, and changing that is wrong since there are already many config like that out there.
https://github.com/redis/redis/runs/1164542228?check_suite_focus=true
Looks like we're gonna have to revert to your previous fix.
And also check that port of 0 means the same (nullify masterhost or skip the line)

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 25, 2020

So,we're gonna revert to the previous fix?

@oranagra
Copy link
Member

How about checking if the port is either "one" (I.e "no one") or "0" (I.e. "127.0.0.1 0") , skip the config like your original fix, but anything else that failed the atoi causing an error?

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 25, 2020

I think if the port is "0",we'll set it to server.masterport,otherwise,anything else that failed the atoi causing an error,right?

@oranagra
Copy link
Member

I think the current (old) behaviour which sets masterhost to non-NULL when getting "127.0.0.1 0" is wrong.
So I think "no one" and "127.0.0.1 0" should pass (leaving server.masterhost unchanged (or setting it to Null), and anything else should error.

Come to think of it, explicitly setting to NULL is better, since it might override a previous statement in the config file, so override is better than skipping.

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 25, 2020

So,we are going to skip "slaveof no one" and "slaveof 127.0.0.1 0" and set server.masterport to NULL,otherwise,anything else that failed the atoi causing an error.right? I think this is a thorough consideration.

@oranagra
Copy link
Member

Sounds like a good plan.
Setting masterhost to NULL (not masterport)
and masterport to 0

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 25, 2020

Just setting masterhost to NULL is enough,i think.

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 27, 2020

It seems that we can't set masterhost to NULL when getting "slaveof 127.0.0.1 0",some tests would fail.

@oranagra
Copy link
Member

i'm sorry, i didn't dig deep enough to see the reason for the previous failure and assumed CONFIG REWRITE generates "127.0.0.1 0" when there's no master.
but i now realized it's a totally different issue. there's a test doing that on purpose in order to create a replica that's unable to connect to it's master.
both failures were actually in the same test, once failing to restart and the other time failing because it became a master:

        # Prevent the slave from receiving master updates, and at
        # the same time send a new script several times to the
        # master, so that we'll end with EVALSHA into the backlog.
        $R($slave_id) slaveof 127.0.0.1 0

        $R($master_id) EVALSHA e6e0b547500efcec21eddb619ac3724081afee89 0
        $R($master_id) EVALSHA e6e0b547500efcec21eddb619ac3724081afee89 0
        $R($master_id) EVALSHA e6e0b547500efcec21eddb619ac3724081afee89 0

        catch {
            $R($slave_id) config rewrite
            restart_server [expr {0-$slave_id}] true
            set R($slave_id) [srv [expr {0-$slave_id}] client]
        }

so since 0 is a now a valid port number, i would like to suggest the following

  1. if the input is no one nullify masterhost and continue
  2. use strtol instead of atoi so that we can detect when the input is not a number.
  3. if strtol failed, goto loaderr

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 27, 2020

I looked at the code for setting the port and found that the author did not verify whether the port is a valid number, but only verified whether the port is between 0 and 65535. Maybe we can maintain a consistent style with it. What do you think?

@oranagra
Copy link
Member

@CaoZB what do you mean by that?

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 27, 2020

I mean
1.if the input is no one nullify masterhost and continue
2.we don't check whether masterport in redis.conf is a valid number
3.just check whether server.msterport is between 0 and 65535 after parsing

@oranagra
Copy link
Member

isn't that exactly what i suggested in my 1,2,3 above?
i.e. in 3 we want to catch both numbers outside the range 0..64k, but also be able to fail when the input s not a number at all (atoi doesn't let us do that)

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 27, 2020

@oranagra Updated,please review it.

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if the change i suggested seem good to you

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 27, 2020

LGTM😄

@oranagra
Copy link
Member

@CaoZB sorry for the ping-pong, please have another looks at my last two commits.

@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 27, 2020

😄I didn't even notice the memory leak.👍

@oranagra oranagra merged commit a295770 into redis:unstable Sep 27, 2020
@CaoZB
Copy link
Contributor Author

CaoZB commented Sep 27, 2020

Thank you for your precious time very much.😄

oranagra added a commit that referenced this pull request Oct 27, 2020
when slaveof config is "no one", reset any pre-existing config and resume.

also solve a memory leak if slaveof appears twice.
and fail loading if port number is out of range or not an integer.

Co-authored-by: caozhengbin <[email protected]>
Co-authored-by: Oran Agra <[email protected]>
(cherry picked from commit a295770)
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Nov 4, 2020
when slaveof config is "no one", reset any pre-existing config and resume.

also solve a memory leak if slaveof appears twice.
and fail loading if port number is out of range or not an integer.

Co-authored-by: caozhengbin <[email protected]>
Co-authored-by: Oran Agra <[email protected]>
jschmieg pushed a commit to memKeyDB/memKeyDB that referenced this pull request Nov 6, 2020
when slaveof config is "no one", reset any pre-existing config and resume.

also solve a memory leak if slaveof appears twice.
and fail loading if port number is out of range or not an integer.

Co-authored-by: caozhengbin <[email protected]>
Co-authored-by: Oran Agra <[email protected]>
(cherry picked from commit a295770)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants