Skip to content

pycriu: intermittent issue when using use_binary #2787

@herheliuk

Description

@herheliuk

When using pycriu with use_binary after a reinstall, I'm getting an error on the first run (only):

pycriu.criu.CRIUExceptionExternal: DUMP failed: Unexpected response type 0: Error(0): Unknown

It is noteworthy that there are no logs in the dump folder.

Steps to reproduce using Ubuntu

Prepare

mkdir ./pycriu-use-binary-bug/ && cd ./pycriu-use-binary-bug/
sudo apt update && sudo apt install -y python3-venv

Reinstall

deactivate
sudo rm -rf * .*
git clone https://github.com/checkpoint-restore/criu ./criu/
sudo bash ./criu/contrib/dependencies/apt-packages.sh
sudo make -C ./criu/ install
python3 -m venv ./env/
source ./env/bin/activate
pip install ./criu/lib/

Adding scripts

test.py

#!/usr/bin/env python3

dumps_dir = './criu_dumps/'

from pycriu import criu as pycriu_criu
from shutil import which as shutil_which
from os import (
    open as os_open,
    close as os_close,
    O_DIRECTORY as os_O_DIRECTORY,
    makedirs as os_makedirs
)
from contextlib import contextmanager

@contextmanager
def open_directory_fd(dir_path: str):
    fd = os_open(dir_path, os_O_DIRECTORY)
    try:
        yield fd
    finally:
        os_close(fd)

criu_binary = shutil_which('criu')

print(f'{dumps_dir=}')
print(f'{criu_binary=}\n')

criu = pycriu_criu()
criu.use_binary(criu_binary)

pid = int(input('Please enter pid to dump: '))

criu.opts.pid = pid
criu.opts.shell_job = True

os_makedirs(dumps_dir, exist_ok=True)

with open_directory_fd(dumps_dir) as fd:
    criu.opts.images_dir_fd = fd
    criu.dump()

print(f'\nSuccessfully dumped {pid}.')

process_to_dump.py

#!/usr/bin/env python3

from os import getpid as os_getpid
from time import sleep as time_sleep

print(f'pid {os_getpid()}\n')

i = 0
    
while i < 100:
    i += 1
    print(i, end=' ', flush=True)
    time_sleep(1)

Run

Terminal 2

source ./env/bin/activate
sudo -E $(which python) test.py

Terminal 3

tmux new-session 'python3 process_to_dump.py'

Notes

If not seeing an error, try again following the steps from Reinstall,
Usually shows up at least every second run, I suggest trying up to 3 times.

Expected behaviour

No errors in terminal 1
& killed process in terminal 2

Same behaviour is expected on recurring runs (scripts can run multiple times).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions