Giter VIP home page Giter VIP logo

Comments (10)

Praetonus avatar Praetonus commented on August 16, 2024 2

The main argument I have for treating this as a bug is that the Linux and OSX implementations currently do opposite things.

from rfcs.

mfelsche avatar mfelsche commented on August 16, 2024

Thanks for reporting.
I quickly wanted to check on this and it is true, that only 1 signal handler is called for 1 distinct signal.

Here is a minimal example to show this behaviour:

use "signals"

actor Main
  new create(env: Env) =>
    let handler1 = SignalHandler(
      object iso is SignalNotify
        fun ref apply(count: U32): Bool =>
          env.out.print("1")
          true
      end,
      Sig.usr1()
    )
    let handler2 = SignalHandler(
      object iso is SignalNotify
        fun ref apply(count: U32): Bool =>
          env.out.print("2")
          true
      end,
      Sig.usr1()
    )
    raise()

  be raise() =>
    SignalRaise(Sig.usr1())

The behaviour on how multiple signal handlers for the same signal behave is not documented in the signals sources or docs. If it were, i would say this should be turned into an RFC, allowing multiple signal handlers for the same signal (with undefined order). But as there is no documentation, this could be handled as a principle of least surprise enhancement without RFC. But maybe others have a different opinion on this.

from rfcs.

Praetonus avatar Praetonus commented on August 16, 2024

After taking a look at the signal implementation (asio/epoll.c and asio/kqueue.c), the behaviour you describe seems to correspond to the OSX implementation. This implementation is, as you point out, not thread safe, and I seem to recall another issue opened about that problem. I can't find it though.

The Linux implementation also has problems, and isn't fully thread safe (though it's better than the OSX implementation). On that platform, the first signal handler registered wins, and cannot be replaced. Every other signal handler created for the same signal will silently do nothing.

In addition, both implementations have a problem with signals like SIGFPE, SIGILL and SIGSEGV (and SIGABRT when raised by abort()), as these signals are required to terminate the program after the signal handler returns. Since our signal handler delegates things to epoll/kqueue, this means that user handlers for these signals won't be called.

The Pony interface in the standard library is problematic as well, as it isn't capability secure. Any function can raise a signal or register a signal handler without first getting the capability to do so.

All in all, I think signals are pretty much broken right now, both from a design and from an implementation standpoint.

Aside from fixing the thread safety issues and the capability security of the interface, I think the questions here are:

  • As @mfelsche said, what should the behaviour be when trying to register multiple signal handlers? If we only allow one at a time, the replacement needs to be capability secure (i.e. a function should need something derived from AmbientAuth in order to replace a signal handler).
  • What should signal handlers for fatal signals look like? Should we even allow users to handle them?

from rfcs.

SeanTAllen avatar SeanTAllen commented on August 16, 2024

from rfcs.

Praetonus avatar Praetonus commented on August 16, 2024

@SeanTAllen It could be handled by the runtime. For example by storing a list of ASIO events for each signal, instead of just one.

from rfcs.

SeanTAllen avatar SeanTAllen commented on August 16, 2024

I wouldnt consider what it does now broken, it it what I as someone unfortunate enough to use signals a lot in the past would expect. That said, if we could normalize that, it would be great.

from rfcs.

SeanTAllen avatar SeanTAllen commented on August 16, 2024

well, Linux and OSX do different things. So I wouldnt call it a bug. But I think that if we can address, that would be a good thing.

from rfcs.

sargun avatar sargun commented on August 16, 2024

@Praetonus I'm somewhat ignorant, since I've only been reading the code for a couple hours, how is the OS X kqueue implementation thread unsafe?

It looks like ponyint_asio_backend_dispatch is executed serially. Is it that pony_asio_event_subscribe has no locking with it and that can create skew?

from rfcs.

mfelsche avatar mfelsche commented on August 16, 2024

We discussed this during sync and decided to move the discussion about how the signal interface should look like to an RFC ticket.

from rfcs.

Praetonus avatar Praetonus commented on August 16, 2024

@sargun Sorry, I forgot to reply to you here. I was incorrect, the OSX implementation is indeed thread safe. The other problems are still relevant, though.

from rfcs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.