Skip to content

flatcar-install: Wait for subproccesses and report errors#99

Merged
pothos merged 2 commits intoflatcar-masterfrom
kai/report-write-error
Jun 26, 2023
Merged

flatcar-install: Wait for subproccesses and report errors#99
pothos merged 2 commits intoflatcar-masterfrom
kai/report-write-error

Conversation

@pothos
Copy link
Copy Markdown
Member

@pothos pothos commented Jun 23, 2023

  • flatcar-install: Wait for subproccesses and report errors

    The redirection of FD 3 to the input FD with >(write_to_disk) causes
    the function to not wait or react on errors from write_to_disk.
    Before returning, wait for all subprocesses to finsh and then check the
    success through the out-of-band FIFO. Since we don't need the waiting
    with a large timeout anymore we can change the wait function to fulfill
    a new purpose.

  • flatcar-install: Function syntax fixes for shellcheck

    While bash allows the function brackes to be missing, shellcheck
    doesn't.
    Add brackets to demark the function body.

How to use

Testing done

truncate -s 10G second_disk.img
./flatcar_production_qemu.sh -- -drive if=virtio,file="$PWD/second_disk.img"

Then scp -r -C -P 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null bin/flatcar-install core@127.0.0.1: and ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 2222 core@127.0.0.1 and in the VM:

sudo ./flatcar-install -s

This worked, then I inserted a false in write_to_disk (after the second dd) and reran sudo ./flatcar-install -d /dev/vdb.
It failed with "write_to_disk: Failed writing image to disk" as expected.
Before this change, it was reporting success even though write_to_disk failed (if the bash issue is absent which causes a timeout of 2 hours due to the trap not working which is another issue) .

Related to flatcar/Flatcar#1059

@pothos pothos force-pushed the kai/report-write-error branch from adc7efe to dec258a Compare June 23, 2023 15:05
@pothos pothos requested a review from a team June 23, 2023 15:25
@@ -702,9 +706,15 @@ function install_from_url() {
[ ${EEND[2]} -ne 0 ] && echo "${EEND[2]}: GPG signature verification failed for ${IMAGE_NAME}" >&2
exit 1
fi 3> >(write_to_disk)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While at it, you probably could fix this hardcoding of file descriptor to 3. It would be better for bash to allocate an unused fd for it with something like this:

local pipefd
exec {pipefd}<> <(:)| tee >(${BZIP_UTIL} -cd >&${pipefd}) \
…
fi ${pipefd}> >(write_to_disk)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, maybe in a separate PR? From what I know the pipe read will behave differently when the pipe was already closed, not sure if this is the case here when using the stdout of : because it terminated already. It could be that something like sleep infinity is better and doesn't lead to reporting EOF early but block as wanted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate PR sounds good.

@krnowak
Copy link
Copy Markdown
Member

krnowak commented Jun 23, 2023

As I understand it - it replaces #97?

@pothos
Copy link
Copy Markdown
Member Author

pothos commented Jun 25, 2023

As I understand it - it replaces #97?

In its current form yes, but I would hope we can leave it open when it instead tackles the other two trap issues with the subshell trick: #97 (review)

@pothos pothos force-pushed the kai/report-write-error branch from c272213 to 3c92619 Compare June 26, 2023 10:43
pothos added 2 commits June 26, 2023 14:27
While bash allows the function brackes to be missing, shellcheck
doesn't.
Add brackets to demark the function body.
The redirection of FD 3 to the input FD with >(write_to_disk) causes
the function to not wait or react on errors from write_to_disk.
Before returning, wait for all subprocesses to finsh and then check the
success through the out-of-band FIFO. Since we don't need the waiting
with a large timeout anymore we can change the wait function to fulfill
a new purpose.
@pothos pothos force-pushed the kai/report-write-error branch from 3c92619 to c1fed40 Compare June 26, 2023 12:28
@pothos pothos requested a review from a team June 26, 2023 12:30
@pothos pothos merged commit e502aab into flatcar-master Jun 26, 2023
@pothos pothos deleted the kai/report-write-error branch June 26, 2023 13:54
pothos added a commit to flatcar/scripts that referenced this pull request Jun 26, 2023
This pulls in
flatcar/init#97
and
flatcar/init#99
to work around a bash regression and add handling for disk write errors.
pothos added a commit to flatcar/scripts that referenced this pull request Jun 27, 2023
This pulls in
flatcar/init#97
and
flatcar/init#99
to work around a bash regression and add handling for disk write errors.
pothos added a commit to flatcar/scripts that referenced this pull request Jun 27, 2023
This pulls in
flatcar/init#97
and
flatcar/init#99
to work around a bash regression and add handling for disk write errors.
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.

2 participants