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

fix Ctrl-C / SIGINT behaviour for pyinstaller-made binaries, fixes #8155 (1.2-maint) #8162

Merged

Conversation

ThomasWaldmann
Copy link
Member

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Mar 28, 2024

Codecov Report

Attention: Patch coverage is 20.00000% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 82.14%. Comparing base (04c8bc6) to head (caba23f).
Report is 3 commits behind head on 1.2-maint.

Files Patch % Lines
src/borg/helpers/process.py 20.00% 8 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@              Coverage Diff              @@
##           1.2-maint    #8162      +/-   ##
=============================================
- Coverage      82.18%   82.14%   -0.04%     
=============================================
  Files             38       38              
  Lines          10831    10838       +7     
  Branches        2077     2079       +2     
=============================================
+ Hits            8901     8903       +2     
- Misses          1368     1373       +5     
  Partials         562      562              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jdchristensen
Copy link
Contributor

This might work to slightly simplify the logic. Untested.

# Set-up:
        self.debounce_interval = 20000000  # ns
       self.last = None

# handler:

        # Ignore a SIGINT if it comes too quickly after the last one, e.g. because it
        # was caused by the same Ctrl-C key press and a parent process forwarded it to us.
       # This can easily happen for the pyinstaller-made binaries because the bootloader
       # process and the borg process are in same process group (see #8155), but maybe also
       # under other circumstances.
       now = time.monotonic_ns()
	if self.last is None: # first SIGINT
            self.last = now
	    self._sig_int_triggered = True
            self._action_triggered = True
        elif now - self.last >= self.debounce_interval: # second SIGINT
            # restore the original signal handler for the 3rd+ SIGINT -
            # this implies that this handler here loses control!
            self.__exit__(None, None, None)
            # handle 2nd SIGINT like the default handler would do it:
            raise KeyboardInterrupt  # python docs say this might show up at an arbitrary place.

@ThomasWaldmann
Copy link
Member Author

@jdchristensen ah, good idea. I just had added a slight fix to not assume zero-based monotonic time, but your suggestion is even better.

@ThomasWaldmann
Copy link
Member Author

@jdchristensen gave it a practical test under linux with a freshly made binary: works!

@ThomasWaldmann ThomasWaldmann merged commit 59e3a02 into borgbackup:1.2-maint Mar 29, 2024
11 checks passed
@ThomasWaldmann ThomasWaldmann deleted the debounce-sigint-1.2 branch March 29, 2024 13:08
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

Successfully merging this pull request may close these issues.

None yet

3 participants