-
Notifications
You must be signed in to change notification settings - Fork 2k
feature(socket.tcp): enhance the logic of parameter verification in #1735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@rainingmaster Please use |
aaffcf0
to
0460b95
Compare
b615f86
to
2d734cb
Compare
Hi @agentzh, I have update the code, make the port optional and accept nil, could you help me review again? |
This pull request is now in conflict :( |
e9737df
to
047e4a7
Compare
content_by_lua_block { | ||
local sock = ngx.socket.tcp() | ||
sock:settimeout(500) | ||
local ok, err = sock:connect("127.0.0.1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this behavior. This may lead to hard-to-debug mistakes. When the host name part is an INET address, the port cannot be optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I agree with this point. So we should allow like this:
sock:connect("unix:/path") -- work
sock:connect("unix:/path", nil) -- work
sock:connect("unix:/path", opt) -- work
sock:connect("127.0.0.1", 80) -- work
sock:connect("127.0.0.1", 80, nil) -- work
sock:connect("127.0.0.1", 80, opt) -- work
But like this will be raise an error:
sock:connect("127.0.0.1", nil) -- error
In this version, the behaviour should be like above: #1735 (comment), but we have to judge the domain is an unix domain or a ip.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rainingmaster My original comment you quoted was for the unix domain socket case, not for the INET case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@agentzh hihi, my quoted should be mean not unix domain socket? so it should mean INET case.
047e4a7
to
df64bb8
Compare
@agentzh @doujiang24 @spacewander Hi, I have raise a new version for this concern, now it will require that the second parameter must be passed in if the Another point to note is that the
IMO, I think this usage should be retained, because users can easily use the format of |
df64bb8
to
6edbfc0
Compare
6edbfc0
to
8fbe9c2
Compare
8fbe9c2
to
b81a279
Compare
In ngx.socket.tcp:connect, if host is a TCP socket, the third parameter could be
nil
, it is to some third part module to write their code like this:But if the host is a unix-domain socket, the second parameter could not be a
nil
, we have to write the code like this:Just like here: https://github.com/openresty/lua-resty-redis/pull/200/files#diff-adb515948c05651051c83fd6fb3ce7ceR143-R149. I think it is a comment use way, so update the second parameter and allow it be nil.