[opam-lib 1.2] Backport the "fix-wait" patch from opam-lib master.
Merge pull request #3217 from samoht/master

[opam-lib 1.2] Backport the "fix-wait" patch from opam-lib master.