Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns-async raises exception "writer fd unexpectedly closed". #146

Closed
1yefuwang1 opened this issue Oct 16, 2017 · 2 comments
Closed

dns-async raises exception "writer fd unexpectedly closed". #146

1yefuwang1 opened this issue Oct 16, 2017 · 2 comments

Comments

@1yefuwang1
Copy link
Contributor

1yefuwang1 commented Oct 16, 2017

After cloning, I type 'make test' on command line, and the following is what I get:

2017-10-16 14:19:16.434280+08:00 5.153.225.51
2017-10-16 14:19:16.440170+08:00 Error ("Exception raised to [Monitor.try_with] that already returned.""This error was captured by a default handler in [Async.Log]."(exn(monitor.ml.Error("Writer error from inner_monitor""writer fd unexpectedly closed "(writer((id 2)(fd((file_descr 5)(info(replaced(("connected to"8.8.8.8:53)(previously_was(socket((family((family PF_INET)(address_of_sockaddr_exn )(sexp_of_address )))(socket_type SOCK_DGRAM)))))))(kind(Socket Active))(supports_nonblock true)(have_set_nonblock true)(state Closed)(watching((read Not_watching)(write Not_watching)))(watching_has_changed false)(num_active_syscalls 0)(close_finished Empty)))(monitor(((name(id 16))(here())(id 16)(has_seen_error false)(is_detached false))((name try_with_or_error)(here())(id 9)(has_seen_error false)(is_detached true))))(inner_monitor(((name(id 17))(here())(id 17)(has_seen_error true)(is_detached true))((name try_with_or_error)(here())(id 9)(has_seen_error false)(is_detached true))))(background_writer_state Stopped_permanently)(background_writer_stopped(Full()))(syscall Per_cycle)(bytes_received 28)(bytes_written 0)(scheduled_bytes 0)(scheduled_back 0)(back 0)(close_state Open)(close_finished Empty)(close_startedEmpty)(num_producers_to_flush_at_close 0)(flush_at_shutdown_elt())(check_buffer_age(((writer )(maximum_age2m)(bytes_received_at_now_minus_maximum_age 0)(bytes_received_queue())(times_received_queue())(bytes_seen 0)(too_old Empty))))(consumer_left Empty)(raise_when_consumer_leaves true)(open_flags(Full(Ok(rdwr nonblock))))(line_ending Unix))))("Caught by monitor (id 16)"))))

Sorry for the bad formatting, I don't know how to pretty-print s-expressions. The message which stands out is ''writer fd unexpectedly closed" . So I did some digging and my guessing is that it is caused by closing fd prematurely before the corresponding writer and reader are closed. The problematic code is:

(* async/async_dns_resolver_unix.ml *)
let cleanfn ?log sock () =
  begin
    try Socket.shutdown sock `Both
    with exn -> Option.iter log ~f:(fun log -> Log.error log "%s" @@ Exn.to_string exn)
  end;
  Monitor.try_with_or_error (fun () -> Unix.close @@ Socket.fd sock) >>| function
  | Error err -> Option.iter log ~f:(fun log -> Log.error log "%s" @@ Error.to_string_hum err)
  | Ok () -> ()

where only the fd is closed, not the corresponding writer nor reader.

@1yefuwang1
Copy link
Contributor Author

1yefuwang1 commented Oct 16, 2017

I have just submitted a pull request to fix this issue. #147
Hope someone review it.

@avsm
Copy link
Member

avsm commented May 9, 2019

the implementation of the 2.0 branch has totally changed in #159, and we need a new async implementation in #161. Closing this in favour of that issue

@avsm avsm closed this as completed May 9, 2019
RyanGibb pushed a commit to RyanGibb/ocaml-dns that referenced this issue Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants