Skip to content

Commit

Permalink
retry on cancelling of getaddrinfo (ruby#11131)
Browse files Browse the repository at this point in the history
When the registerred unblock function is called, it should retry
the cancelled blocking function if possible after checkints.

For example, `SIGCHLD` can cancel this method, but it should not
raise any exception if there is no trap handlers.

The following is repro-code:

```ruby
require 'socket'
PN = 10_000

1000000.times{
  p _1
  PN.times{
    fork{
      sleep rand(0.3)
    }
  }
  i = 0
  while i<PN
    cpid = Process.wait -1, Process::WNOHANG
    if cpid
      # p [i, cpid]
      i += 1
    end

    begin
      TCPServer.new(nil, 0).close
    rescue
      p $!
      exit!
    end
  end
}
```
  • Loading branch information
ko1 authored Jul 9, 2024
1 parent be1089c commit 3427a16
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/socket/raddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ rb_getaddrinfo(const char *hostp, const char *portp, const struct addrinfo *hint
if (err == 0) *ai = arg->ai;
}
else if (arg->cancelled) {
err = EAI_AGAIN;
retry = 1;
}
else {
// If already interrupted, rb_thread_call_without_gvl2 may return without calling wait_getaddrinfo.
Expand Down Expand Up @@ -731,7 +731,7 @@ rb_getnameinfo(const struct sockaddr *sa, socklen_t salen,
}
}
else if (arg->cancelled) {
err = EAI_AGAIN;
retry = 1;
}
else {
// If already interrupted, rb_thread_call_without_gvl2 may return without calling wait_getnameinfo.
Expand Down

0 comments on commit 3427a16

Please sign in to comment.