Skip to content

TCP proxy does not need to rely on the event loop for the backend connection #448

Closed

Description

@Geal

currently, all calls to connect_to_backend are made from:

pub fn connect_to_backend(&mut self, token: ClientToken) {
let add = self.from_client_add();
let res = {
let cl = self.clients[token].clone();
let cl2: Rc<RefCell<ProxyClientCast>> = self.clients[token].clone();
let protocol = { cl.borrow().protocol() };
let entry = self.clients.vacant_entry();
if entry.is_none() {
error!("not enough memory, cannot connect to backend");
return;
}
let entry = entry.unwrap();
let entry = entry.insert(cl);
let back_token = Token(entry.index().0 + add);
let res = match protocol {
Protocol::TCP => {
if let Some(mut tcp) = self.tcp.take() {
let mut b = cl2.borrow_mut();
let client: &mut tcp::Client = b.as_tcp() ;
let r = tcp.connect_to_backend(&mut self.poll, client, back_token);
self.tcp = Some(tcp);
r
} else {
Err(ConnectionError::HostNotFound)
}
},
Protocol::HTTP => {
if let Some(mut http) = self.http.take() {
let mut b = cl2.borrow_mut();
let client: &mut http::Client = b.as_http() ;
let r = http.connect_to_backend(&mut self.poll, client, back_token);
self.http = Some(http);
r
} else {
Err(ConnectionError::HostNotFound)
}
},
Protocol::HTTPS => {
if let Some(mut https) = self.https.take() {
let r = https.connect_to_backend(&mut self.poll, cl2, back_token);
self.https = Some(https);
r
} else {
Err(ConnectionError::HostNotFound)
}
},
_ => {
panic!("should not call connect_to_backend on listeners");
},
};
if res != Ok(BackendConnectAction::New) {
entry.remove();
}
res
};
match res {
Ok(BackendConnectAction::Reuse) => {
debug!("keepalive, reusing backend connection");
}
Ok(BackendConnectAction::Replace) => {
},
Ok(BackendConnectAction::New) => {
},
Err(ConnectionError::HostNotFound) | Err(ConnectionError::NoBackendAvailable) | Err(ConnectionError::HttpsRedirect) => {
},
_ => self.close_client(token),
}
}

But the TCP proxy could connect directly during the accept() call. There's already a special case here:

if should_connect {
self.connect_to_backend(client_token);
}

We could have the event loop pass 2 tokens and add another entry for the backend connection

Activity

  1. Geal commented on Apr 19, 2018

    @Geal
    MemberAuthor

    This issue is probably linked to #444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions