IoSocketHandleImpl::close()#5171
Conversation
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com> Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com> Signed-off-by: Dan Zhang <danzh@google.com>
5503f68 to
f26fc1e
Compare
Signed-off-by: Dan Zhang <danzh@google.com> Signed-off-by: Dan Zhang <danzh@google.com>
c9a3af8 to
4b1c922
Compare
|
/retest |
|
🔨 rebuilding |
include/envoy/api/os_sys_calls.h
Outdated
| * @see man 2 connect | ||
| */ | ||
| virtual SysCallIntResult connect(int sockfd, const struct sockaddr* serv_addr, | ||
| socklen_t addrlen) PURE; |
There was a problem hiding this comment.
Do you plan to send in a follow-up PR that updates existing calls to ::getsockname, ::getpeername, ::connect, etc.?
There was a problem hiding this comment.
Either me or @sbelair2 will do, but yes, there will be follow-up pr's to use IoHandle interface instead of operating on fd directly.
| } | ||
|
|
||
| SysCallIntResult FdIoHandleImpl::getSocketName(sockaddr* addr, socklen_t* addr_len) { | ||
|
|
There was a problem hiding this comment.
nit: remove extra line break.
There was a problem hiding this comment.
done in io_socket_handle_impl.cc
| namespace Envoy { | ||
| namespace Network { | ||
|
|
||
| class FdIoHandleImpl : public virtual IoHandle { |
There was a problem hiding this comment.
nit: I think we can skip the virtual keyword.
There was a problem hiding this comment.
done in io_socket_handle_impl.cc
|
@danzh2010 how does this relate to #5128? Is this a separate implementation? Can you please sync up with @sbelair2 to reconcile? I would like to only review a single sequence of changes on this topic. Thank you! |
|
I originally mean to only send this PR to sbelair2 for discussion about the interface and the fd specific implementation. I think he can either merge mine into his current PR or submitting his as is and I can extend it with this one. We will definitely sync up on slack. Sorry for the confusion. |
|
/sub |
|
I'm going on vacation for 4 weeks. How can I prevent this PR from becoming stale and closed? |
|
You can just re-open it when you return, come back to this page and comment and click "Reopen and comment". |
|
My apologies for taking so long. As I said in our private communication, I have converted IoHandlePtr to a unique_ptr but cannot get things to work: 59 tests all fail quickly with an illegal instruction: 4. I’ve been going through my code and don’t see it, and it is very difficult to debug- am in the process of setting up a vm and trying to catch it in gdb.
When are you going on vacation? And can’t the PR be re-opened? Btw, the PR will have moved on past this point by then, no matter what.
From: danzh <notifications@github.com>
Reply-To: envoyproxy/envoy <reply@reply.github.com>
Date: Wednesday, December 12, 2018 at 9:38 AM
To: envoyproxy/envoy <envoy@noreply.github.com>
Cc: "Stephen Belair (sbelair)" <sbelair@cisco.com>, Mention <mention@noreply.github.com>
Subject: Re: [envoyproxy/envoy] Add an IoHandle interface (#5171)
I'm going on vacation for 4 weeks. How can I prevent this PR from becoming stale and closed?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#5171 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ADxdgc3cFava-xPw93TdYwwjy3CD7IKxks5u4T8BgaJpZM4Y8azp>.
|
|
I think only maintainers get a "re-open" button. But one of us can do that for you. One concern I have with this family of PRs is that I feel a holistic design incorporating abstraction of libevent is needed. It is hard for me to evaluate any of these PRs if ultimately they still have to interface with libevent, which exposes FDs at the interface. |
| IoHandlePtr FdIoHandleImpl::socket(int domain, int type, int protocol) { | ||
| SysCallIntResult result = Api::OsSysCallsSingleton::get().socket(domain, type, protocol); | ||
| RELEASE_ASSERT(result.rc_ != -1, ""); | ||
| return IoHandlePtr(new FdIoHandleImpl(result.rc_)); |
There was a problem hiding this comment.
make_unique<>() would be easier on the eye.
There was a problem hiding this comment.
done in io_socket_handle_impl.cc
|
|
||
| Api::SysCallIntResult close() override; | ||
|
|
||
| bool isClosed() override; |
There was a problem hiding this comment.
count be bool isClosed() const override;
There was a problem hiding this comment.
Technically, most methods (all that do not change the fd_) could be marked const, but maybe should do so only on methods that do not modify the underlying socket.
Obviously this change should be made on the base class first.
There was a problem hiding this comment.
done in io_socket_handle_impl.* and io_handle.h
|
This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
|
This pull request has been automatically closed because it has not had activity in the last 14 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
|
/assign @sbelair2 |
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
mattklein123
left a comment
There was a problem hiding this comment.
Thanks I think this approach is great. A few small comments.
/wait
include/envoy/network/io_handle.h
Outdated
| // frequent memory allocation of IoError instance. | ||
| // If this is used, IoHandleCallResult has to be instantiated with a deleter that does not | ||
| // deallocate memory for this error. | ||
| #define ENVOY_ERROR_AGAIN reinterpret_cast<IoError*>(1) |
There was a problem hiding this comment.
nit: Is it possible to use a constexpr here vs. a define?
There was a problem hiding this comment.
not done. constexpr doesn't like reinterpret_cast.
include/envoy/network/io_handle.h
Outdated
| // Map platform specific error into IoErrorCode. | ||
| // Needed to hide errorCode() in case of ENVOY_ERROR_AGAIN. | ||
| static IoErrorCode getErrorCode(const IoError* err) { | ||
| ASSERT(err != nullptr); |
There was a problem hiding this comment.
nit: Can we just make this function take a reference to avoid this assert? Same elsewhere in similar cases?
There was a problem hiding this comment.
I think *ENVOY_ERROR_AGAIN will cause crash.
There was a problem hiding this comment.
It won't crash actually, from the computer perspective a pointer and reference are the same thing, it won't crash until you actually try to access the memory (I'm 99% sure). I would go ahead and switch to a reference assuming it works.
There was a problem hiding this comment.
Yeah, you're right. I switched to use reference here.
If the caller try to dereference a nullptr, we will have seg fault. Is this more preferred than ASSERT?
There was a problem hiding this comment.
Yeah in general we prefer references for things that can't be null. In this case, I don't consider ENVOY_ERROR_AGAIN to be null.
| IoError::IoErrorCode IoSocketError::errorCode() const { | ||
| switch (errno_) { | ||
| case EAGAIN: | ||
| RELEASE_ASSERT(false, "EAGAIN should use specific error ENVOY_ERROR_AGAIN"); |
There was a problem hiding this comment.
Can we just swap with NOT_REACHED?
| const int rc = ::close(fd_); | ||
| fd_ = -1; | ||
| IoErrorPtr err(nullptr, deleteIoError); | ||
| if (rc == -1) { |
There was a problem hiding this comment.
Can this ever actually fail? It definitely can't return EAGAIN I don't think. Can we just RELEASE_ASSERT that is doesn't fail instead of having this code?
There was a problem hiding this comment.
Yes, it couldn't be EAGAIN for sure. But it can fail according t linux man.
There was a problem hiding this comment.
I think it can only fail if passed a bad handle though, which should never happen. I would just RELEASE_ASSERT it personally.
There was a problem hiding this comment.
RELEASE_ASSERT will fail test/common/network/connection_impl_test.cc because most of the io_handle objects in the test are initialized manually with invalid fd like 0 or 1.
I removed the if (rc == -1 ) block and return rc as is.
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
|
/retest |
|
🔨 rebuilding |
|
mac build failure: ERROR: /Users/distiller/project/test/common/upstream/BUILD:167:1: Linking of rule '//test/common/upstream:load_stats_reporter_test' failed (Exit 1) cc_wrapper.sh failed: error executing command ... This seems unrelated to this PR |
|
@danzh2010 don't worry about it, but if you need more changes merge master and I think it will go away. |
mattklein123
left a comment
There was a problem hiding this comment.
LGTM, let's see if we can shift pointers to references, if not we can ship! Thank you!
include/envoy/network/io_handle.h
Outdated
| // Map platform specific error into IoErrorCode. | ||
| // Needed to hide errorCode() in case of ENVOY_ERROR_AGAIN. | ||
| static IoErrorCode getErrorCode(const IoError* err) { | ||
| ASSERT(err != nullptr); |
There was a problem hiding this comment.
It won't crash actually, from the computer perspective a pointer and reference are the same thing, it won't crash until you actually try to access the memory (I'm 99% sure). I would go ahead and switch to a reference assuming it works.
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
This is hard to achieve in #6037, given that os_sys_calls is used by the caller, and the readv/writev interface already diverged from syscall's interface. |
thanks, I'll take a look cc @yaelharel |
Signed-off-by: Dan Zhang <danzh@google.com> Signed-off-by: Fred Douglas <fredlas@google.com>
Implement IoSocketHandleImpl::close(). And replace the use of ::close(int fd) with it everywhere.
Risk Level: low.
Test: Rely on existing tests. If there are ::close(fd) left out, ~IoHandle() should have caused double close on same fd in tests.
Part of #4546 #2557