@@ -229,6 +229,7 @@ struct fast_fallback_inetsock_arg
229
229
rb_nativethread_lock_t * lock ;
230
230
struct fast_fallback_getaddrinfo_entry * getaddrinfo_entries [2 ];
231
231
struct fast_fallback_getaddrinfo_shared * getaddrinfo_shared ;
232
+ int wait ;
232
233
int connection_attempt_fds_size ;
233
234
int * connection_attempt_fds ;
234
235
VALUE test_mode_settings ;
@@ -313,7 +314,7 @@ cancel_fast_fallback(void *ptr)
313
314
{
314
315
arg -> cancelled = true;
315
316
char notification = SELECT_CANCELLED ;
316
- if ((write (arg -> notify , & notification , 1 )) < 0 ) {
317
+ if (arg -> notify != -1 && (write (arg -> notify , & notification , 1 )) < 0 ) {
317
318
rb_syserr_fail (errno , "write(2)" );
318
319
}
319
320
}
@@ -554,7 +555,7 @@ init_fast_fallback_inetsock_internal(VALUE v)
554
555
pthread_t threads [arg -> family_size ];
555
556
char resolved_type [2 ];
556
557
ssize_t resolved_type_size ;
557
- int hostname_resolution_waiter = 0 , hostname_resolution_notifier = 0 ;
558
+ int hostname_resolution_waiter = -1 , hostname_resolution_notifier = -1 ;
558
559
int pipefd [2 ];
559
560
fd_set readfds , writefds ;
560
561
@@ -587,6 +588,7 @@ init_fast_fallback_inetsock_internal(VALUE v)
587
588
if ((fcntl (hostname_resolution_waiter , F_SETFL , waiter_flags | O_NONBLOCK )) < 0 ) {
588
589
rb_syserr_fail (errno , "fcntl(2)" );
589
590
}
591
+ arg -> wait = hostname_resolution_waiter ;
590
592
591
593
hostname_resolution_notifier = pipefd [1 ];
592
594
wait_arg .readfds = & readfds ;
@@ -599,7 +601,6 @@ init_fast_fallback_inetsock_internal(VALUE v)
599
601
rb_nativethread_lock_initialize (arg -> getaddrinfo_shared -> lock );
600
602
601
603
arg -> getaddrinfo_shared -> notify = hostname_resolution_notifier ;
602
- arg -> getaddrinfo_shared -> wait = hostname_resolution_waiter ;
603
604
arg -> getaddrinfo_shared -> connection_attempt_fds = arg -> connection_attempt_fds ;
604
605
arg -> getaddrinfo_shared -> connection_attempt_fds_size = arg -> connection_attempt_fds_size ;
605
606
arg -> getaddrinfo_shared -> cancelled = false;
@@ -1191,6 +1192,10 @@ fast_fallback_inetsock_cleanup(VALUE v)
1191
1192
arg -> local .res = 0 ;
1192
1193
}
1193
1194
1195
+ if (arg -> wait != -1 ) close (arg -> wait );
1196
+ if (getaddrinfo_shared -> notify != -1 ) close (getaddrinfo_shared -> notify );
1197
+ getaddrinfo_shared -> notify = -1 ;
1198
+
1194
1199
if (getaddrinfo_shared ) {
1195
1200
if (arg -> family_size == 1 ) {
1196
1201
free_fast_fallback_getaddrinfo_shared (& getaddrinfo_shared );
0 commit comments