From 29606b1e5e14902e6b1ac706507e7fa9878adb70 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 17 Nov 2017 13:01:45 -0700 Subject: [PATCH] fix cleanup of `tcp-connect` connection state Repairs another regression due to the rktio conversion, where a connection that takes a while can be mismanaged, especially if multiple connection attempts run concurrently. --- racket/src/racket/src/network.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/racket/src/racket/src/network.c b/racket/src/racket/src/network.c index a0c78ae1d0..ef1cc90119 100644 --- a/racket/src/racket/src/network.c +++ b/racket/src/racket/src/network.c @@ -766,6 +766,10 @@ static void connect_cleanup(Connect_Progress_Data *pd) rktio_addrinfo_lookup_stop(scheme_rktio, pd->lookup); pd->lookup = NULL; } + if (pd->trying_s) { + (void)scheme_rktio_fd_to_semaphore(pd->trying_s, MZFD_REMOVE); + pd->trying_s = NULL; + } if (pd->connect) { rktio_connect_stop(scheme_rktio, pd->connect); pd->connect = NULL; @@ -778,10 +782,6 @@ static void connect_cleanup(Connect_Progress_Data *pd) rktio_addrinfo_free(scheme_rktio, pd->src_addr); pd->src_addr = NULL; } - if (pd->trying_s) { - (void)scheme_rktio_fd_to_semaphore(pd->trying_s, MZFD_REMOVE); - pd->trying_s = NULL; - } if (pd->s) { (void)scheme_rktio_fd_to_semaphore(pd->s, MZFD_REMOVE); rktio_close(scheme_rktio, pd->s); @@ -890,7 +890,7 @@ static int tcp_check_connect(Connect_Progress_Data *pd, Scheme_Schedule_Info *si s = rktio_connect_trying(scheme_rktio, pd->connect); pd->trying_s = s; } - + if (!sinfo || !sinfo->is_poll) { if (pd->trying_s) if (!check_fd_sema(pd->trying_s, MZFD_CHECK_WRITE, sinfo, NULL)) @@ -1014,8 +1014,10 @@ static Scheme_Object *tcp_connect(int argc, Scheme_Object *argv[]) END_ESCAPEABLE(); } - if (pd->trying_s) + if (pd->trying_s) { (void)scheme_rktio_fd_to_semaphore(pd->trying_s, MZFD_REMOVE); + pd->trying_s = NULL; + } s = rktio_connect_finish(scheme_rktio, connect); @@ -1028,7 +1030,7 @@ static Scheme_Object *tcp_connect(int argc, Scheme_Object *argv[]) pd->connect = NULL; if (!s) - connect_failed(pd, NULL, address, id); + connect_failed(pd, NULL, address, id); connect_cleanup(pd);