classification
Title: Set the SA_ONSTACK in PyOS_setsig to play well with other VMs like Golang
Type: resource usage Stage: commit review
Components: Interpreter Core Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: gregory.p.smith
Priority: normal Keywords: patch

Created on 2021-03-03 17:45 by gregory.p.smith, last changed 2021-03-05 05:52 by gregory.p.smith. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24730 merged gregory.p.smith, 2021-03-03 18:01
Messages (3)
msg388036 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2021-03-03 17:45
PyOS_setsig currently sets the struct sigaction context.sa_flags = 0 before calling sigaction.

Other virtual machines such as Golang depend on signals using SA_ONSTACK such that signal handlers use a specially allocated stack that runtime sets up for reliability reasons as they use tiny stacks on normal threads.

SA_ONSTACK is a no-op flag in the typical case where no sigaltstack() call has been made to setup an alternate signal handling stack.  (as in 99.99% of all CPython applications)

When a C/C++ extension module is linked with cgo to call into a Golang library, doing this increases reliability.

As much as I try to dissuade anyone from creating and relying on hidden complexity multi-VM-hybrids in a single process like this, some people do, and this one line change helps.

Golang references:
  https://golang.org/pkg/os/signal/#hdr-Go_programs_that_use_cgo_or_SWIG
 and
  https://go-review.googlesource.com/c/go/+/298269/ (which clarifies that SA_RESTART is no longer a requirement. Good. Because Python won't get along well with that one.)
msg388145 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2021-03-05 05:49
New changeset 02ac6f41e5569ec28d625bb005155903f64cc9ee by Gregory P. Smith in branch 'master':
bpo-43390: Set SA_ONSTACK in PyOS_setsig (GH-24730)
https://github.com/python/cpython/commit/02ac6f41e5569ec28d625bb005155903f64cc9ee
msg388146 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2021-03-05 05:52
I expect zero fallout from this given the semantics.  SA_ONSTACK really appears to be something that should've been the POSIX default since it was introduced as a feature in ~BSD4.2 in the early 80s.  But it never was.

It'll be good to have in the beta releases to see if anyone pipes up.

We'll be running our interpreter inside Google with this flag enabled.
History
Date User Action Args
2021-03-05 05:52:11gregory.p.smithsetstatus: open -> closed
resolution: fixed
messages: + msg388146

stage: patch review -> commit review
2021-03-05 05:49:37gregory.p.smithsetmessages: + msg388145
2021-03-03 18:03:32gregory.p.smithsettype: resource usage
2021-03-03 18:01:13gregory.p.smithsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23502
2021-03-03 17:45:04gregory.p.smithcreate