lib/pull: Wait for pending ops to complete on error
authorColin Walters <walters@verbum.org>
Mon, 18 Sep 2017 16:08:48 +0000 (12:08 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Tue, 19 Sep 2017 19:05:26 +0000 (19:05 +0000)
commit5c4f26bd65b492e795ac8f9a5081fba4e60a3d42
tree003618a803e39855f0ab95de4e5000fed79891af
parent3e564116b26992fa68f82abb3da08f7572151554
lib/pull: Wait for pending ops to complete on error

I saw in a stack trace that the main thread was calling `exit()` even while
worker threads were alive and doing sha256/write/fsync etc. for objects.

The stack trace was a SEGV as the main thread was calling into library
`atexit()` handlers and we were a liblz4 destructor:

```
 #0  0x00007f2db790f8d4 _fini (liblz4.so.1)
 #1  0x00007f2dbbae1c68 __run_exit_handlers (libc.so.6)
```

(Why that library has a destructor I don't know offhand, can't find
 it in the source in a quick look)

Anyways, global library destructors and worker threads continuing simply don't
mix. Let's wait for our outstanding operations before we exit. This is also a
good idea for projects using libostree as a shared library, as we don't want
worker threads outliving operations.

Our existing pull corruption tests exercise coverage here.

I added a new `caught-error` status boolean to the progress API, and use it the
commandline to tell the user that we're waiting for outstanding ops.

Closes: #1185
Approved by: jlebon
src/libostree/ostree-repo-pull.c
src/libostree/ostree-repo.c