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

HPCC-17017 Add port info to socket tracename #10196

Merged
merged 1 commit into from Jul 10, 2017

Conversation

mckellyln
Copy link
Contributor

Signed-off-by: Mark Kelly mark.kelly@lexisnexisrisk.com

Type of change:

  • This change is a bug fix (non-breaking change which fixes an issue).
  • This change is a new feature (non-breaking change which adds functionality).
  • This change is a breaking change (fix or feature that will cause existing behavior to change).
  • This change alters the query API (existing queries will have to be recompiled)

Checklist:

  • My code follows the code style of this project.
    • My code does not create any new warnings from compiler, build system, or lint.
  • The commit message is properly formatted and free of typos.
    • The commit message title makes sense in a changelog, by itself.
    • The commit is signed.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly, or...
    • I have created a JIRA ticket to update the documentation.
    • Any new interfaces or exported functions are appropriately commented.
  • I have read the CONTRIBUTORS document.
  • The change has been fully tested:
    • I have added tests to cover my changes.
    • All new and existing tests passed.
    • I have checked that this change does not introduce memory leaks.
    • I have used Valgrind or similar tools to check for potential issues.
  • I have given due consideration to all of the following potential concerns:
    • Scalability
    • Performance
    • Security
    • Thread-safety
    • Premature optimization
    • Existing deployed queries will not be broken
    • This change fixes the problem, not just the symptom
    • The target branch of this pull request is appropriate for such a change.
  • There are no similar instances of the same problem that should be addressed
    • I have addressed them here
    • I have raised JIRA issues to address them separately
  • This is a user interface / front-end modification
    • I have tested my changes in multiple modern browers
    • The component(s) render as expected

Testing:

Full QA suite passed.

@hpcc-jirabot
Copy link

strcpy(lname, "(NULL)");
lport = 1;
e->Release();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not related to original enhancement but discovered this and took the opportunity to add try/catch around name().

Copy link
Member

Choose a reason for hiding this comment

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

what about other places that call name() , e.g. logConnectionInfo

Should name() always catch and behave like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

logConnectionInfo may be ok as its always after a successful connect and if there is an error then throwing may make sense. I will wrap it in try / catch and ignore error if you think that is better.
But in general case - should name() throw ? I am not sure.

@richardkchapman
Copy link
Member

@jakesmith Please review. Any performance concerns?


free(tracename);
tracename = strdup(peer);
tracename = strdup(peer.str());
Copy link
Member

Choose a reason for hiding this comment

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

Not new, but this would be better as:

tracename = peer.detach();

peer.append(name?name:"(NULL)");
peer.append(":").append(hostport);
if (sock != INVALID_SOCKET)
peer.append(" (").append(sock).append(")");
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't feel like this should be done here (in setTraceName), but rather by the caller (Can common up elsewhere if same pattern).
e.g., CSocket::CSocket(const SocketEndpoint &ep, ... ,with name where trace name is "T>"
will have target port already and can use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lport is local port, hostport is remote port, good to see both and sock fd in trace.

catch (IException *e)
{
strcpy(lname, "(NULL)");
lport = 1;
Copy link
Member

Choose a reason for hiding this comment

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

why 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, should be -1

strcpy(lname, "(NULL)");
lport = 1;
e->Release();
}
Copy link
Member

Choose a reason for hiding this comment

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

what about other places that call name() , e.g. logConnectionInfo

Should name() always catch and behave like this?

@@ -2662,7 +2687,7 @@ CSocket::CSocket(const SocketEndpoint &ep,SOCKETMODE smode,const char *name)
SocketEndpoint self;
self.setLocalHost(0);
self.getUrlStr(hostname);
setTraceName("S>", hostname);
setTraceName("S>", hostname.str());
Copy link
Member

Choose a reason for hiding this comment

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

fine, but not strictly necessary, const char * cast operator will call str() automatically.


free(tracename);
tracename = strdup(peer);
tracename = peer.detach();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

used detach()

strcpy(lname, "(NULL)");
lport = -1;
e->Release();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added try / catch here also

@mckellyln
Copy link
Contributor Author

@jakesmith code updated as per review comments and discussion.

@@ -893,6 +894,8 @@ int CSocket::post_connect ()
nagling = true;
set_nagle(false);
state = ss_open;
char lname[256];
localPort = name(lname, sizeof(lname), false);
Copy link
Member

Choose a reason for hiding this comment

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

a slight waste getting lname when not needed.
CSocket::name() should fill in a StringBuffer really too, which it does internally, only to copy to the fixed sized passed in buffer.
You could change it to 2 methods:

void CSocket::getEndpoint(SocketEndpoint &ep); 
unsigned CSocket::getName(StringBuffer &name);

and use getEndpoint() here.

Same is true of CSocket::peer_name()

Copy link
Member

Choose a reason for hiding this comment

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

The oktothrow=false, is it anymore expect to throw an exception here than anywhere else?
The previously (prior to this commit) it would throw because called too early.

@@ -234,9 +234,9 @@ class CSecureSocket : implements ISecureSocket, public CInterface
}

// Get name of accepted socket and returns port
virtual int name(char *name,size32_t namemax)
virtual int name(char *name, size32_t namemax, bool oktothrow=true)
Copy link
Member

Choose a reason for hiding this comment

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

minor: could use override

char peer[256];
peer_name(peer,sizeof(peer));
hostport = peer_name(peer,sizeof(peer));
hostname = strdup(peer);
Copy link
Member

Choose a reason for hiding this comment

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

can remove:

hostname = NULL;
hostport = 0;

early on in constructor

hostport = peer_name(peer,sizeof(peer));
hostname = strdup(peer);
char lname[256];
localPort = name(lname, sizeof(lname), false);
Copy link
Member

Choose a reason for hiding this comment

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

It may not be an efficient concern, but as per prev. comment (in post_connect) it would look cleaner if method didn't get lname that it didn't need.

Unless it would be useful to store? I notice e.g. logConnectionInfo used to use, but you removed?

char rname[256];
int rport = peer_name(rname, sizeof(rname));
PROGLOG("SOCKTRACE: connect(%u) - time:%u ms fd:%d l:%s:%d r:%s:%d", timeoutms, conn_mstime, sock, lname, lport, rname, rport);
PROGLOG("SOCKTRACE: connect(%u) - time:%u ms fd:%d l:%d r:%s:%d", timeoutms, conn_mstime, sock, localPort, hostname, hostport);
Copy link
Member

Choose a reason for hiding this comment

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

was logging lname not useful?

@jakesmith
Copy link
Member

@mckellyln - a few comments.

Am not sure about the CSocket::name change (oktothrow).
see comment where oktothrow=false.
i.e. is it really more expected to throw an exception in that context than others?
If not, then why ignore in that 1 case not others.
Probably should throw there too (?) Socket is open by then now, so should succeed.
If should succeed (as with other contexts) then don't need oktothrow.

@mckellyln mckellyln force-pushed the hpcc-17017 branch 3 times, most recently from da27589 to bbd297a Compare July 7, 2017 15:24
@mckellyln
Copy link
Contributor Author

@jakesmith updated as per comments for re-review.

@@ -331,6 +331,9 @@ class jlib_decl ISocket : extends IInterface
// Get peer ip of socket - in UDP returns return addr
virtual IpAddress &getPeerAddress(IpAddress &addr)=0;

// Get local endpoint of socket
virtual SocketEndpoint &getEndpoint(SocketEndpoint &ep)=0;
Copy link
Member

Choose a reason for hiding this comment

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

trivial: could be const method, but other existing methods (e.g. getPeerAddress) should be too.

@@ -257,6 +257,12 @@ class CSecureSocket : implements ISecureSocket, public CInterface
return m_socket->getPeerAddress(addr);
}

// Get local endpoint of socket
virtual SocketEndpoint &getEndpoint(SocketEndpoint &ep)
Copy link
Member

Choose a reason for hiding this comment

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

could be const + override.

@jakesmith
Copy link
Member

A couple of trivial comment, but looks good to merge now.
@richardkchapman

@mckellyln
Copy link
Contributor Author

@jakesmith added const + override to new functions. If you are ok with last commit, I will squash all commits.

@jakesmith
Copy link
Member

@mckellyln - Yes looks good, go ahead and squash.

Signed-off-by: Mark Kelly <mark.kelly@lexisnexisrisk.com>
@mckellyln
Copy link
Contributor Author

@jakesmith, @richardkchapman squashed and ready for merge.

@HPCCSmoketest
Copy link
Contributor

Automated Smoketest: ✅
Sha: 25e388e
Build: success
Build: success
ECL Watch: Rebuilding Site

errors warnings build time
0 65 92.98 seconds

Install hpccsystems-platform-community_6.4.0-rc5.el7.x86_64.rpm
HPCC Start: OK

Unit tests result:

Test total passed failed errors timeout
unittest 94 94 0 0 0
wutoolTest(Dali) 19 19 0 0 0
wutoolTest(Cassandra) 19 19 0 0 0

Regression test result:

phase total pass fail
setup (hthor) 11 11 0
setup (thor) 11 11 0
setup (roxie) 11 11 0
test (hthor) 733 733 0
test (thor) 627 627 0
test (roxie) 760 760 0

HPCC Stop: OK
HPCC Uninstall: OK

@richardkchapman richardkchapman merged commit 5f116f8 into hpcc-systems:candidate-6.4.0 Jul 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants