Postmortem of a fun couple bugs
Tags: tech, go, dbus, bugs
Published: 2023-02-01 02:36:27

---
title: Postmortem of a fun couple bugs
published: true
date: 2021-11-11 19:55:00 UTC
tags: Tech,Go,dbus,bugs
canonical_url: https://tyrel.dev/blog/2021/11/postmortem-of-a-fun-couple-bugs.html
---

Story at my previous job:

> Tieg: Hey Tyrel, I can't run <tt>invoke sign 5555</tt>, can you help with this?

This is How my night started last night at 10pm. My coworker Tieg did some work on our [CLI](https://tidelift.com/cli) project and was trying to release the latest version. We use [invoke](https://www.pyinvoke.org/) to run our code signing and deployment scripts, so I thought it was just a quick "oh maybe I screwed up some python!" fix. It wasn't.

I spent from 10:30 until 1:30am this morning going through and looking into why Tieg wasn't able to sign the code. The first thing I did was re-run the build on CircleCI, which had the same error, so hey! at least it was reproducible. The problem was that in our Makefile scripts we run <tt>tidelift version &gt; <span>tidelift-cli.version</span></tt> and then upload that to our deployment directories, but this was failing for some reason. We let clients download this file to see what the latest version is and then our CLI tool has the ability to selfupdate (except on homebrew) to pull this latest version if you're outdated.

Once I knew what was failing, I was able to use CircleCI's ssh commands and log in, and see what happened, but I was getting some other errors. I was seeing some problems with <tt><span>dbus-launch</span></tt> so I promptly (mistakenly) yelled to the void on twitter about <tt><span>dubs-launch</span></tt>. Well would you know it, I may have mentioned before, but I work with Havoc Pennington.

> Havoc Pennington: fortunately I wrote dbus-launch so may be able to tell you something, unfortunately it was like 15 years ago

Pumped about this new revelation, I started looking at our <tt>keychain</tt> dependency, because I thought the issue was there as that's the only thing that uses <tt>dbus</tt> on Linux. Then we decided (Havoc Pointed it out) that it was a red herring, and maybe the problem was elsewhere. I at least learned a bit about dbus and what it does, but not enough to really talk about it to any detail.

Would you know it, the problem was elsewhere. Tieg was running <tt>dtruss</tt> and saw that one time it was checking his <tt>/etc/hosts</tt> file when it was failing, and another time it was NOT, which was passing. Then pointed out a 50ms lookup to our <tt>download.tidelift.com</tt> host.

Tieg then found [Issue 49517](https://github.com/golang/go/issues/49517) this issue where someone mentions that Go 1.17.3 was failing them for net/http calls, but not the right way.

It turns out, that it wasn't the keyring stuff, it wasn't the _technically_ the version calls that failed. What was happening is every command starts with a check to [https://download.tidelift.com/cli/tidelift-cli.version](https://download.tidelift.com/cli/tidelift-cli.version) which we then compare to the current running version, if it's different and outdated, we then say "you can run selfupdate!". What fails is that call to download.tidelift.com, because of compiling with go1.17.3 and a <tt>context canceled</tt> due to stream cleanup I guess?

Okay so we need to downgrade to Go 1.17.2 to fix this. Last night in my trying, I noticed that our CircleCI config was using <tt>circle/golang:1.16</tt> as its docker image, which has been superseded by <tt>cimg/go:1.16.x</tt> style of images. But I ran into some problems with that while upgrading to <tt>cimg/go:1.17.x</tt>. The problem was due to the image having different permissions, so I couldn't write to the same directories that when Mike wrote our <tt>config.yml</tt> file, worked properly.

Tieg and I did a paired zoom chat and finished this up by cutting out all the testing/scanning stuff in our config files, and just getting down to the Build and Deploy steps. Found ANOTHER bug that Build seems to run as the <tt>circleci</tt> user, but Deploy was running as <tt>root</tt>. So in the build <tt>working_directory</tt> setting, using a <tt>~/go/tidelift/cli</tt> path, worked. But when we restored the saved cache to Deploy, it still put it in <tt>/home/circle/go/tidelift/cli</tt>, but then the <tt>working_directory</tt> of <tt>~/go/tidelift/cli</tt> was relative to <tt>/root/</tt>. What a nightmare!

All tildes expanded to <tt>/home/circleci/go/tidelift/cli</tt> set, Makefile hacks undone, (removing windows+darwin+arm64 builds from your scripts during testing makes things A LOT faster!) and PR Merged, we were ready to roll.

I merged the PR, we cut a new version of TideliftCLI 1.2.5, updated the changelog and signed sealed delivered a new version which uses Go 1.17.2, writes the proper <tt><span>tidelift-cli.version</span></tt> file in deployment steps, and we were ready to ROCK!

That was fun day. Now it's time to write some rspec tests.