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
Update Unix Domain Socket creation/handling #1852
Conversation
Hi, Thanks for the contribution! Could you please fix the formatting (indentation should be 4 spaces)? Also one of the test is failing: lt-test_term_endpoint: ../tests/test_term_endpoint.cpp:148: int main(): Assertion `rc == 0' failed. I suspect it's due to the changes in zmq::ipc_listener_t::set_address from return -1 to goto error; |
int rc; | ||
|
||
if ( s != -1 ) { | ||
zmq_assert (s != retired_fd); |
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.
retired_fd is -1, so this check doesn't make much sense. Why the added "if {}" block?
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.
On Mon, Mar 14, 2016 at 9:08 AM, Luca Boccassi notifications@github.com wrote:
In src/ipc_listener.cpp:
@@ -208,9 +260,13 @@ int zmq::ipc_listener_t::set_address (const char *addr_)
int zmq::ipc_listener_t::close ()
{
- zmq_assert (s != retired_fd);
- int rc = ::close (s);
- errno_assert (rc == 0);
- int rc;
- if ( s != -1 ) {
zmq_assert (s != retired_fd);
retired_fd is -1, so this check doesn't make much sense. Why the added "if {}" block?
I'm trying to handle the case where the directory for the socket
failed to be created (i.e. mkdtemp() failed), then s would remain -1.
This would cause the assertion error "s != retired_fd" and casue
::close to return an error with errno set to EBADF. Though I suppose
this is also the case if open_socket() failed as well. So it seems
that in the case of either mkdtemp() or open_socket() failing, we
don't want the assertion or ::close() failure here.
Pete
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.
Yes, and that's why, I think, the code as-is did a return -1 instead of goto err if open_socket failed.
We need the assert to enforce that this API is not used improperly, IE: called on a socket that's already closed. Do you think it's possible to leave that in with your changes?
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.
On Mon, Mar 14, 2016 at 10:51 AM, Luca Boccassi
notifications@github.com wrote:
Yes, and that's why, I think, the code as-is did a return -1 instead of goto err if open_socket failed.
We need the assert to enforce that this API is not used improperly, IE: called on a socket that's already closed. Do you think it's possible to leave that in with your changes?
I may need to rework it a bit. What I was trying to do was cleanup
the mkdtemp() on an error. I thought that re-using
ipc_listener_t::close() was the best way to do that.
I can revert ipc_listener_t::close(), and update
ipc_listener_t::set_address() to properly cleanup the directory if
open_socket() fails. I understand your API checks, and I'll fix
things on my end.
Are the prohibitions on the use of exceptions? I initially coded it
to throw an exception in create_wildcard_address(), but didn't see
handling of exceptions elsewhere. If exceptions are ok, I can rework
set_address() to make sure that there are no stray files or
directories upon failure pretty easily. Otherwise, the code may look
a bit ugly.
Pete
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 may need to rework it a bit. What I was trying to do was cleanup
the mkdtemp() on an error. I thought that re-using
ipc_listener_t::close() was the best way to do that.
If you need more time, I can merge as-is for now, and then you can send another PR to fix it when it's ready. Or maybe it's easier for you to work on the same branch?
I can revert ipc_listener_t::close(), and update
ipc_listener_t::set_address() to properly cleanup the directory if
open_socket() fails. I understand your API checks, and I'll fix
things on my end.Are the prohibitions on the use of exceptions? I initially coded it
to throw an exception in create_wildcard_address(), but didn't see
handling of exceptions elsewhere. If exceptions are ok, I can rework
set_address() to make sure that there are no stray files or
directories upon failure pretty easily. Otherwise, the code may look
a bit ugly.
I personally don't have any objections to exceptions, but it's true that they are not used anywhere else. @hintjens any objections/opinions on exceptions?
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.
On Mon, Mar 14, 2016 at 11:10 AM, Luca Boccassi
notifications@github.com wrote:
If you need more time, I can merge as-is for now, and then you can send another PR to fix it when it's ready. Or maybe it's easier for you to work on the same branch?
I can wait until I get things into a shape that meets with your
approval. No point in checking in "sorta" code.
I personally don't have any objections to exceptions, but it's true that they are not used anywhere else. @hintjens any objections/opinions on exceptions?
Well, if they aren't commonly used, it probably isn't that helpful to
divert from the common style already in use. I'll rework it without
exceptions.
Pete
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.
On Mon, Mar 14, 2016 at 11:10 AM, Luca Boccassi
notifications@github.com wrote:
If you need more time, I can merge as-is for now, and then you can send
another PR to fix it when it's ready. Or maybe it's easier for you to work
on the same branch?
Actually, the cleanup was far easier than I thought. I reverted the
goto's back to returning -1, but also cleaning up any created
directory. I also reverted the API checks at the beginning of
ipc_listener_t::close() to the prior checks. I also added code to
preserve errno when trying to cleanup in these cases.
I also have the formatting cleaned up, and tweaked my code to have
opening braces on the same line (to match the rest of the file).
Pete
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.
Awesome, thank you very much for taking the time to tweak the PR!
On Mon, Mar 14, 2016 at 9:04 AM, Luca Boccassi notifications@github.com wrote:
I've fixed that on my branch. I'll send a new pull request once I've
Hmm.... Looking at the test, this shouldn't be the case. My change Pete |
Thanks for looking into it! In case you're not too familiar with Github, you can amend your commit and push -f to the same branch, and this PR will get updated automatically. |
On Mon, Mar 14, 2016 at 9:04 AM, Luca Boccassi notifications@github.com wrote:
This failure is multifaceted. The root cause of the failure is that I think the reason they were passing before and began failing with my I've fixed test_term_endpoint. However, I have two XFAIL's that I |
On Mon, Mar 14, 2016 at 9:58 AM, Luca Boccassi notifications@github.com wrote:
I'm not git expert, but I did manage two squash my commits into a Pete |
On 14 March 2016 at 17:47, Suudy notifications@github.com wrote:
It does seem a bit forced, yes. Thanks for taking care of it.
Yes you can ignore those 2: XFAIL in autotools means it's marked as an |
…ories, and cleanup afterward. Fix test_term_endpoint handling of optvallen
Update Unix Domain Socket creation/handling
@Suudy - sorry to ping you again, but the same test is still failing on OSX:
https://travis-ci.org/zeromq/libzmq/jobs/115954957 Any idea what could be the problem? |
Never mind, it was the path buffer size, which becomes very long on OSX. Fix via: #1853 |
FYI: this is what the TMP path looks like on OSX:
|
Out of curiosity, is TMP, TMPDIR, or TEMPDIR defined in the environment? On Wed, Mar 16, 2016 at 2:47 PM, Luca Boccassi notifications@github.com
|
TMPDIR is set to: /var/folders/gw/_2jq29095y7b__wtby9dg_5h0000gn/T/ See log: https://travis-ci.org/bluca/libzmq/builds/116755306 |
Ah. I can back out the environment check and use the current working On Thursday, March 17, 2016, Luca Boccassi notifications@github.com wrote:
|
No need to, I think it's fine as long as we know it can happen and the test has a big enough buffer, which it now has. |
It might be better to use FILENAME_MAX (from cstdio) for the buffer On Thu, Mar 17, 2016 at 2:51 PM, Luca Boccassi notifications@github.com
|
Good idea, that's even better. Thanks! |
Done. Pull request #1857 has been created. On Thu, Mar 17, 2016 at 3:01 PM, Luca Boccassi notifications@github.com
|
Updated handling of Unix Domain Sockets, make use of temporary directories, and cleanup afterward.