]> git.lizzy.rs Git - rust.git/commitdiff
rustuv: Fix a tcp connect timeout bug on windows
authorAlex Crichton <alex@alexcrichton.com>
Sun, 20 Apr 2014 04:39:30 +0000 (21:39 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 20 Apr 2014 04:39:30 +0000 (21:39 -0700)
When a uv_tcp_t is closed in libuv, it will still invoke the pending connect_cb,
and I thought that it would always call it with ECANCELED, but it turns out that
sometimes we'll get a different error code instead. Handle this case by checking
to see if the request's data is NULL and bail out if so (the timeout expired).

src/librustuv/net.rs

index cbda25485c737074439eb7b43cea7b61d76b6c45..69d978b24334fec56c0ae1dea0e5970478e42f56 100644 (file)
@@ -270,7 +270,14 @@ struct Ctx {
             let req = Request::wrap(req);
             if status == uvll::ECANCELED { return }
 
-            let cx: &mut Ctx = unsafe { req.get_data() };
+            // Apparently on windows when the handle is closed this callback may
+            // not be invoked with ECANCELED but rather another error code.
+            // Either ways, if the data is null, then our timeout has expired
+            // and there's nothing we can do.
+            let data = unsafe { uvll::get_data_for_req(req.handle) };
+            if data.is_null() { return }
+
+            let cx: &mut Ctx = unsafe { &mut *(data as *mut Ctx) };
             cx.status = status;
             match cx.timer {
                 Some(ref mut t) => t.stop(),