Repository navigation
Closed
Description
currently, all calls to connect_to_backend are made from:
Lines 737 to 807 in 563f1ba
| 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:
Lines 721 to 723 in 563f1ba
| 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
Metadata
Metadata
Assignees
Labels
No labels
Activity
Geal commentedon Apr 19, 2018
This issue is probably linked to #444