]> Witch of Git - web/blog/blob - posts/2017/package-manager-race-condition.md
Minify inline CSS, move syntax colors to bottom of page
[web/blog] / posts / 2017 / package-manager-race-condition.md
1 ---
2 title: "You Got Your Race Condition Inside My Package Manager!"
3 date: 2017-08-14
4 author: Cassie Jones
5 summary: "We solve a fun, surreal debugging mystery involving pip and version compatibility."
6 ---
7
8 # A Case of Broken Builds
9
10 The continuous integration servers at my current job are unfortunately stateful.
11 Every week or so, we run a bunch of configuration processes to reinstall packages to keep the environment clean.
12 One of these reinstalls `pip` and the Python libraries used by build tools.
13 This morning, I got a message from one of the build engineers telling me that the Python libraries weren't installing correctly anymore.
14 (Even though I'm an intern, I'm apparently one of the office Python experts now.)
15 So, I opened up the build log, and began looking around.
16
17 What was failing was pretty clear:
18
19 ```
20 Collecting ruamel.yaml
21 Using cached ruamel.yaml-0.15.28.tar.gz
22 Installing collected packages: ruamel.yaml
23 ...
24 error: Microsoft Visual C++ 9.0 is required
25 ```
26
27 but why was this suddenly happening now, without us making any changes to our configuration?
28 Also, why are we installing ruamel.yaml?
29 We're not using that!
30
31 Long story short, ruamel.yaml was a transitive dependency of dateparser, an excellent library for parsing natural language dates.
32 It wasn't clear to me why it would be suddenly failing though, so I decided to go investigating further.
33 Looking at the release notes of dateparser, I saw that they had recently pinned ruamel.yaml to `<0.14`, which we clearly weren't getting.
34 Previously, the version was un-pinned, so I decided to go look at the release notes for ruamel.yaml, and sure enough, there were releases over the weekend—those must've been what broke it.
35
36 We upgraded our dependency on dateparser to 0.6, and tried again... and it still failed while trying to build the newest version of ruamel.yaml.
37 One period of looking at GitHub blame views, commit histories, and unpacking PyPI tarballs later, I determined that version 0.6 of dateparser released on PyPI doesn't actually have the pin the version of ruamel.yaml, despite what the changelog claims.
38 (I opened [dateparser issue #342][] for this.)
39
40 Since the version wasn't pinned, we just asked pip to first install an older version of ruamel.yaml, to hopefully get priority when dateparser tried to install it.
41 So, we put `ruamel.yaml==0.13.14` in our package list, and then tried again.
42 Finally, everything worked perfectly.
43
44 Case closed.
45
46 ---
47
48 # This Fix is a Mystery
49
50 But wait, what's this?
51 Looking closer at the successful build logs, we can see that both `ruamel.yaml-0.13.14` and `ruamel.yaml-0.15.29` are installing without complaint.
52 What's stopped the error?
53 Well, if you'll look at the version number up at the top, we were installing `ruamel.yaml-0.15.28` before—just one hour previously, while I was on my lunch break, an update to ruamel.yaml had been released.
54 Looking back at previous versions on PyPI, I finally figured out what had gone wrong.
55 If you look at the downloads on the PyPI page for [ruamel.yaml version 0.15.28][0.15.28], you'll see that there are no Windows wheels.
56 (Wheels are the format that Python uses to distribute compiled C extensions and pre-packed libraries.)
57 However, if you go to the page for [version 0.15.29][0.15.29], then you'll see that Windows wheels are finally present.
58 So, I guess until dateparser fixes their version pinning, we'll just have to hope that ruamel.yaml stays packaged correctly.
59
60 Case closed.
61
62 ---
63
64 # We Get Very Unlucky
65
66 Oops, nope it's not.
67 Later in the afternoon, I got another message that some of the builds had failed.
68 Looking at the first build that started failing, again we see that...
69
70 ```
71 Collecting ruamel.yaml
72 Using cached ruamel.yaml-0.15.30.tar.gz
73 Installing collected packages: ruamel.yaml
74 ...
75 error: Microsoft Visual C++ 9.0 is required
76 ```
77
78 okay, this project releases *fast*, this is the fourth release in 2 days.
79 In any case, the last few builds succeeded with `0.15.30`, so what happened?
80 Well, I don't know for sure, but I have a pretty good guess.
81 I suspect that the release process for ruamel.yaml isn't atomic, and that they upload their source releases first, and the wheels come a bit later.
82 We were unlucky enough to start a build during that first upload, where only the source package was available, and no Windows wheels.
83 But, the few builds that got held up and started 4 minutes after the others took long enough that the wheels were available, and so they installed without any fuss.
84
85 This was an exceptionally unlucky situation.
86 But, I've got a very good story now—and also a much greater appreciation for various package manager `.lock` files.
87
88 [dateparser issue #342]: https://github.com/scrapinghub/dateparser/issues/342
89 [0.15.28]: https://pypi.python.org/pypi/ruamel.yaml/0.15.28
90 [0.15.29]: https://pypi.python.org/pypi/ruamel.yaml/0.15.29