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

Cannot recover using python >=3.8 on macOS #838

Closed
mikewallace1979 opened this issue Aug 30, 2023 · 9 comments
Closed

Cannot recover using python >=3.8 on macOS #838

mikewallace1979 opened this issue Aug 30, 2023 · 9 comments

Comments

@mikewallace1979
Copy link
Contributor

mikewallace1979 commented Aug 30, 2023

Recovery currently fails when running Barman on Python 3.11 on macOS.

Originally reported on the mailing list and reproducible by creating a python 3.11 virtualenv and attempting to recover a backup:

$ barman recover mt-primary 20210705T100000 /tmp/recovered
Starting local restore for server mt-primary using backup 20210705T100000
Destination directory: /tmp/recovered
        16616, foo, /tmp/tablespace
Copying the base backup.
EXCEPTION: Can't pickle local object 'Command.make_logging_handler.<locals>.handler'
See log file for more details.

This is not an issue using earlier versions of python on macOS and it also does not appear to be an issue with python 3.11 on non macOS systems.


Update: After further testing this is an issue all the way back to python 3.8 on macOS.

@mikewallace1979
Copy link
Contributor Author

For completeness I should note that the Barman project is developed primarily for Linux systems and we do not support macOS.

@mikewallace1979 mikewallace1979 changed the title Cannot recover using python 3.11 on macOS Cannot recover using python >=3.8 on macOS Aug 30, 2023
@ARCICT
Copy link

ARCICT commented Aug 31, 2023

Came across the following links. I taught it might help to resolve the issue.

The possible root cause of the issue:
https://medium.com/devopss-hole/python-multiprocessing-pickle-issue-e2d35ccf96a9

And maybe a solution can be found here:
https://stackoverflow.com/questions/72766345/attributeerror-cant-pickle-local-object-in-multiprocessing

@ARCICT
Copy link

ARCICT commented Sep 4, 2023

Info in the light of the upcoming python 3.12 release:

Look for multiprocessing in https://docs.python.org/3.12/whatsnew/3.12.html

@mikewallace1979
Copy link
Contributor Author

@ARCICT Thanks for looking into this - I think you are correct about the possible root cause, given the recovery code uses multiprocessing.Pool.imap_unordered to spawn copy jobs, and that the issue only affects macOS on Python versions >= 3.8.

For confirmation I tried setting multiprocessing.set_start_method("fork") in Barman and this allows recovery to complete.

We'll need a bit of time to figure out the best solution and, going by the Python 3.12 release notes (thanks again for the heads-up about that one), it looks like we're going to need to solve it if we want Barman to continue working under Linux on Python 12 and later.

@ARCICT
Copy link

ARCICT commented Sep 6, 2023

Mike,
-a python novices question. Where can we set/patch 'multiprocessing.set_start_method("fork")' ? we would like to build with the last version of python and be able to restore

@mikewallace1979
Copy link
Contributor Author

Hi @ARCICT - I added a set_start_method in barman.cli.main, like this:

diff --git a/barman/cli.py b/barman/cli.py
index 2b0fcef9..14e9fb0d 100644
--- a/barman/cli.py
+++ b/barman/cli.py
@@ -2110,6 +2110,9 @@ def main():
     """
     The main method of Barman
     """
+    import multiprocessing
+
+    multiprocessing.set_start_method("fork")
     # noinspection PyBroadException
     try:
         argcomplete.autocomplete(p)

I'm hesitant to propose this as the long term solution because of the comments about the safety of fork which I haven't had a chance to read up on yet - it might be better to change the code run under multiprocessing so that it can be pickled, allowing it to work with spawn. For now the above patch should at least allow barman recover to complete.

@ARCICT
Copy link

ARCICT commented Sep 7, 2023

@mike,
Thanks for the info.
I agree that this is neither a good nor longterm solution. But at least it allows us to use the latest python version and still be able to use the restore function.
I read somewhere ( and I can't find the link) that a possible work around is be to set "cores 1" . . . which means that no multiprocessing will be used. Neither a longterm solution;-)
We 'll do some restores in this setup and see how fast we come across issues.

Regarding the good longterm solution we are looking at the python wizards :-)
Marc

@gcalacoci
Copy link
Contributor

@ARCICT I've created a PR that should solve the issue of Pickle and macOS:

#843

can you please check if is working as expected for you? With this patch, I've been able to backup and restore using rsync on macOS using Python 3.8.11 and should work with the newer versions

@ARCICT
Copy link

ARCICT commented Sep 14, 2023

@gcalacoci Guilio, Works like a charm !
Many thanks (to all) for the swift respons & fix !

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

No branches or pull requests

3 participants