Skip to content

Commit c03d658

Browse files
committed
auto merge of #13638 : alexcrichton/rust/fix-windows-tcp-timeout-bug, r=brson
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).
2 parents 92f6b92 + 5bfb260 commit c03d658

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/librustuv/net.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,14 @@ impl TcpWatcher {
270270
let req = Request::wrap(req);
271271
if status == uvll::ECANCELED { return }
272272

273-
let cx: &mut Ctx = unsafe { req.get_data() };
273+
// Apparently on windows when the handle is closed this callback may
274+
// not be invoked with ECANCELED but rather another error code.
275+
// Either ways, if the data is null, then our timeout has expired
276+
// and there's nothing we can do.
277+
let data = unsafe { uvll::get_data_for_req(req.handle) };
278+
if data.is_null() { return }
279+
280+
let cx: &mut Ctx = unsafe { &mut *(data as *mut Ctx) };
274281
cx.status = status;
275282
match cx.timer {
276283
Some(ref mut t) => t.stop(),

0 commit comments

Comments
 (0)