fix(http): stackoverflow in Conn::ready

I've had a couple of instances during stress testing now where
Conn::ready would overflow its stack due to recursing on itself. This
moves subsequent calls to ready() into a loop outside the function.
This commit is contained in:
Joe Wilm
2016-10-06 17:23:18 -07:00
parent 8672ec5a36
commit c32d0e9adf
4 changed files with 58 additions and 20 deletions

View File

@@ -14,7 +14,7 @@ use std::time::Duration;
use rotor::{self, Scope, EventSet, PollOpt};
use header::Host;
use http::{self, Next, RequestHead};
use http::{self, Next, RequestHead, ReadyResult};
use net::Transport;
use uri::RequestUri;
use {Url};
@@ -467,9 +467,16 @@ where C: Connect,
fn ready(self, events: EventSet, scope: &mut Scope<Self::Context>) -> rotor::Response<Self, Self::Seed> {
match self {
ClientFsm::Socket(conn) => {
let res = conn.ready(events, scope);
let now = scope.now();
conn_response!(scope, res, now)
let mut conn = Some(conn);
loop {
match conn.take().unwrap().ready(events, scope) {
ReadyResult::Done(res) => {
let now = scope.now();
return conn_response!(scope, res, now);
},
ReadyResult::Continue(c) => conn = Some(c),
}
}
},
ClientFsm::Connecting(mut seed) => {
if events.is_error() || events.is_hup() {