Skip to content
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

DISPATCH-960 - Resolving service port when using http listener #294

Merged
merged 1 commit into from Jul 23, 2020

Conversation

fgiorgetti
Copy link
Contributor

As suggested by @ted-ross, I am re-submitting this PR again now using getservbyname_r which is multi-thread safe.

If you find any other possible issue, please let me know.

src/amqp.c Outdated
@@ -73,11 +76,30 @@ const char * const QD_AMQP_COND_FRAME_SIZE_TOO_SMALL = "amqp:frame-size-too-smal
const char * const QD_AMQP_PORT_STR = "5672";
const char * const QD_AMQPS_PORT_STR = "5671";

const char * const QD_AMQP_DFLT_PROTO = "tcp";

int qd_port_int(const char* port_str) {
if (!strcmp(port_str, QD_AMQP_PORT_STR)) return QD_AMQP_PORT_INT;
Copy link
Member

Choose a reason for hiding this comment

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

I understand that this is not part of the pull request, but aren't these lines (with strcmp) redundant with the strtoul below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Maybe I should submit a new PR without the strcmp, as service name is now being resolved when strtoul returns 0. And also, using static values for amqp/amqps can also be a problem, in case someone changes the default values at /etc/services (no supposed to happen, but it is possible).

@fgiorgetti
Copy link
Contributor Author

Removed as suggested. It seems to be working just fine for me.

Copy link
Contributor

@jiridanek jiridanek left a comment

Choose a reason for hiding this comment

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

I tried it and it works. The only problem is that when I use nonsensical symbolic port name, such as asdfgh, I get running dispatch with listener on a random port, instead of an error.

After merging the doctest PR, I'd like to look into this more and see if I can fix anything, with the help of unittests.

char *buf = calloc(buf_len, sizeof(char));

// Service port is resolved
if ( !getservbyname_r(port_str, QD_AMQP_DFLT_PROTO, &serv_info, buf, buf_len, &serv_info_res) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also check if serv_info_res == NULL.

if ( !getservbyname_r(port_str, QD_AMQP_DFLT_PROTO, &serv_info, buf, buf_len, &serv_info_res) ) {
n = ntohs(serv_info.s_port);
} else {
n = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

n is unsigned, so assigning -1 to it is wrong

@jiridanek jiridanek merged commit b46405d into apache:master Jul 23, 2020
char *buf = calloc(buf_len, sizeof(char));

// Service port is resolved
if ( !getservbyname_r(port_str, QD_AMQP_DFLT_PROTO, &serv_info, buf, buf_len, &serv_info_res) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, getservbyname_r is unavailable on macOS, there getservbyname is already reentrant.

@gemmellr
Copy link
Member

@jiridanek Im confused by the updates here. You left comments suggesting there are things needing fixed with this, but then merged it without adjusting those bits yourself, and the JIRA is still just 'Open'. Was the merge an accident?

@jiridanek
Copy link
Contributor

jiridanek commented Jul 23, 2020

@gemmellr It already does what it is supposed to do, so I thought it is ready to be merged. The improvement is there, macOS travis job is allowed to fail, and the behavior on invalid protocol name is not any worse than it was before.

I did not close the Jira because I was planning to revisit the issue regarding my comments, either myself when there is the c_unittests pr merged, which should be soon now, or see if @fgiorgetti maybe fixes it in the meantime.

edit: if what I've done is questionable, which I acknowledge it probably is, I'll learn for the future. Anyways, i wouldn't've spotted the macOS failure until I rebased and merged the PR, because the PR is older than the macOS job in Travis.

@gemmellr
Copy link
Member

Ok. If there are comments like 'x is wrong', 'should also do x', and 'gets a random port instead of error when doing ' (I was unclear if that was also true previously or not, but it seems like part of the same issue ither way) I'd personally leave it unmerged until addressed one way or anotehr by someone or other...or perhaps resolve the original JIRA and raise another to consider as seperate issues later if not important.

Fair re: OSX failure and the job not existing (rebases can always be pushed to forks for testing first though hehe)

struct servent serv_info;
struct servent *serv_info_res;
int buf_len = 4096;
char *buf = calloc(buf_len, sizeof(char));
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be allocated on stack, so alloca or enum {buf_len = 4096 }; char buf[buf_len];

@jiridanek
Copy link
Contributor

This PR is a resubmit of #284.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants