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
HPCC-17017 Add port info to socket tracename #10196
Conversation
https://track.hpccsystems.com/browse/HPCC-17017 |
system/jlib/jsocket.cpp
Outdated
strcpy(lname, "(NULL)"); | ||
lport = 1; | ||
e->Release(); | ||
} |
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.
Not related to original enhancement but discovered this and took the opportunity to add try/catch around name().
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.
what about other places that call name() , e.g. logConnectionInfo
Should name() always catch and behave like this?
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.
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.
@jakesmith Please review. Any performance concerns? |
system/jlib/jsocket.cpp
Outdated
|
||
free(tracename); | ||
tracename = strdup(peer); | ||
tracename = strdup(peer.str()); |
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.
Not new, but this would be better as:
tracename = peer.detach();
system/jlib/jsocket.cpp
Outdated
peer.append(name?name:"(NULL)"); | ||
peer.append(":").append(hostport); | ||
if (sock != INVALID_SOCKET) | ||
peer.append(" (").append(sock).append(")"); |
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.
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.
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.
lport is local port, hostport is remote port, good to see both and sock fd in trace.
system/jlib/jsocket.cpp
Outdated
catch (IException *e) | ||
{ | ||
strcpy(lname, "(NULL)"); | ||
lport = 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.
why 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.
sorry, should be -1
system/jlib/jsocket.cpp
Outdated
strcpy(lname, "(NULL)"); | ||
lport = 1; | ||
e->Release(); | ||
} |
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.
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()); |
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.
fine, but not strictly necessary, const char * cast operator will call str() automatically.
|
||
free(tracename); | ||
tracename = strdup(peer); | ||
tracename = peer.detach(); |
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.
used detach()
system/jlib/jsocket.cpp
Outdated
strcpy(lname, "(NULL)"); | ||
lport = -1; | ||
e->Release(); | ||
} |
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.
Added try / catch here also
@jakesmith code updated as per review comments and discussion. |
system/jlib/jsocket.cpp
Outdated
@@ -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); |
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.
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()
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.
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) |
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.
minor: could use override
char peer[256]; | ||
peer_name(peer,sizeof(peer)); | ||
hostport = peer_name(peer,sizeof(peer)); | ||
hostname = strdup(peer); |
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.
can remove:
hostname = NULL;
hostport = 0;
early on in constructor
system/jlib/jsocket.cpp
Outdated
hostport = peer_name(peer,sizeof(peer)); | ||
hostname = strdup(peer); | ||
char lname[256]; | ||
localPort = name(lname, sizeof(lname), false); |
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.
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?
system/jlib/jsocket.cpp
Outdated
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); |
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.
was logging lname not useful?
@mckellyln - a few comments. Am not sure about the CSocket::name change (oktothrow). |
da27589
to
bbd297a
Compare
@jakesmith updated as per comments for re-review. |
system/jlib/jsocket.hpp
Outdated
@@ -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; |
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.
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) |
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.
could be const + override.
A couple of trivial comment, but looks good to merge now. |
@jakesmith added const + override to new functions. If you are ok with last commit, I will squash all commits. |
@mckellyln - Yes looks good, go ahead and squash. |
Signed-off-by: Mark Kelly <mark.kelly@lexisnexisrisk.com>
@jakesmith, @richardkchapman squashed and ready for merge. |
Automated Smoketest: ✅
Install hpccsystems-platform-community_6.4.0-rc5.el7.x86_64.rpm Unit tests result:
Regression test result:
HPCC Stop: OK |
Signed-off-by: Mark Kelly mark.kelly@lexisnexisrisk.com
Type of change:
Checklist:
Testing:
Full QA suite passed.