Skip to content

Commit

Permalink
network: support combined read|write event when connecting. (#1896)
Browse files Browse the repository at this point in the history
This breaks protocols in which servers can send initial data,
because read readiness might be reported during "connected" event.

Fixes #1895.

Signed-off-by: Piotr Sikora <[email protected]>
  • Loading branch information
PiotrSikora authored and mattklein123 committed Oct 19, 2017
1 parent 22f5202 commit ff36ab2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions source/common/network/connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,16 +385,14 @@ void ConnectionImpl::onFileEvent(uint32_t events) {
return;
}

// Read may become ready if there is an error connecting. If still connecting, skip straight
// to write ready which is where the connection logic is.
if (!(state_ & InternalState::Connecting) && (events & Event::FileReadyType::Read)) {
onReadReady();
if (events & Event::FileReadyType::Write) {
onWriteReady();
}

// It's possible for a read event callback to close the socket (which will cause fd_ to be -1).
// It's possible for a write event callback to close the socket (which will cause fd_ to be -1).
// In this case ignore write event processing.
if (fd_ != -1 && (events & Event::FileReadyType::Write)) {
onWriteReady();
if (fd_ != -1 && (events & Event::FileReadyType::Read)) {
onReadReady();
}
}

Expand Down Expand Up @@ -435,6 +433,8 @@ ConnectionImpl::IoResult ConnectionImpl::doReadFromSocket() {
}

void ConnectionImpl::onReadReady() {
ENVOY_CONN_LOG(trace, "read ready", *this);

ASSERT(!(state_ & InternalState::Connecting));

IoResult result = doReadFromSocket();
Expand Down

0 comments on commit ff36ab2

Please sign in to comment.