Using `blockUserSignals` is unnecessary and it will probably be deprecated

Đang mở
#385 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
30/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, haskell
Lĩnh vực
operating-systems

Hướng nghiên cứu

Start with the fork and signal-handling code in cbits/posix/fork_exec.c, including the surrounding comments and calls to blockUserSignals, unblockUserSignals, stopTimer and startTimer. Work out how the signal mask and shared pipe behave in the parent and child before choosing an approach. Done means the fork path handles signals safely without relying on the RTS functions this issue proposes removing.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

The blockUserSignals / unblockUserSignals functions are exported from the RTS. These functions are (almost certainly) vestiges of an long since gone design in the (non-threaded) RTS for signal handling. The RTS probably does not need them any more any they will probably be deprecated and removed. See GHC ticket #27968

They are used however in cbits/posix/fork_exec.c before/after the fork(). The surrounding comments explain:

    // Block signals with Haskell handlers.  The danger here is that
    // with the threaded RTS, a signal arrives in the child process,
    // the RTS writes the signal information into the pipe (which is
    // shared between parent and child), and the parent behaves as if
    // the signal had been raised.
    blockUserSignals();

    // See #4074.  Sometimes fork() gets interrupted by the timer
    // signal and keeps restarting indefinitely.
    stopTimer();

    int pid = fork();
    switch(pid)
    {
    case -1:
        unblockUserSignals();
        startTimer();
    case 0:
        ...
        unblockUserSignals();
        ...
    default
        ...
        unblockUserSignals();
        ...

So it gets blocked in the parent process's thread before fork() and then gets unblocked again in the parent and child processes later.

This is not wrong. But surely there is a less complicated solution: block all signals before the fork, have that signal mask be inherited in the child, sort out the shared pipes and then restore the previous signal mask in the child. And similarly restore it in the parent after the fork too. There is no need to be so selective about the signals to be masked. It's rather a close coupling with the RTS, which is fine if it's necessary but here it is not.

Incidentally, it's not immediately obvious to me that the use of unblockUserSignals in the child is in a place that solves the problem that the comment identifies. Surely we need to do something to stop the sharing of the pipe, or something. I don't see anything that resolves the problem before the unblockUserSignals call.

This looks to be related to #384. Not using unblockUserSignals at all would presumably avoid any problem with shared users of unblockUserSignals.

Also related: startTimer and stopTimer are no-ops from GHC 10 and are thus deprecated. The RTS no longer uses signals for its timer. The C functions don't yet have deprecation warnings, but they probably will soon.

Ngôn ngữ chính
Haskell
Star
91
Fork
93
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của haskell/process

Tất cả issue của haskell/process

Issue tương tự

Thêm issue về Haskell

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.