CodeSOD: Going Crazy

Date:

Share:

For months, everything at Yusuf's company was fine. Then, suddenly, he comes in to the office to learn that overnight the log exploded with thousands of panic messages. No software changes had been pushed, no major configurations had happened- just a reboot. What had gone wrong?

This particular function was invoked as part of the application startup:

func (a *App) setupDocDBClient(ctx context.Context) error {
	docdbClient, err := docdb.NewClient(
		ctx,
		a.config.MongoConfig.URI,
		a.config.MongoConfig.Database,
		a.config.MongoConfig.EnableTLS,
	)
	if err != nil {
		return nil
	}

	a.DocDBClient = docdbClient
	return nil
}

This is Go, which passes errors as part of the return. You can see an example where docdb.NewClient returns a client and an err object. At one point in the history of this function, it did the same thing- if connecting to the database failed, it returned an error.

But a few months earlier, an engineer changed it to swallow the error- if an error occurred, it would return nil.

As an organization, they did code reviews. Multiple people looked at this and signed off- or, more likely, multiple people clicked a button to say they'd looked at it, but hadn't.

Most of the time, there weren't any connection issues. But sometimes there were. One reboot had a flaky moment with connecting, and the error was ignored. Later on in execution, downstream modules started failing, which eventually lead to a log full of panic level messages.

The change was part of a commit tagged merely: "Refactoring". Something got factored, good and hard, all right.

[Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.

Source link

Subscribe to our magazine

━ more like this

nukeop/nuclear: Streaming music player that finds free music for you

Desktop music player focused on streaming from free sources Official website Downloads Documentation Mastodon Twitter Support channel (Matrix): #nuclear:matrix.org Discord chat: https://discord.gg/JqPjKxE Suggest and vote on new features here: https://nuclear.featureupvote.com/ Readme translations: nuclear...

PostSecret Live! in Australia – PostSecret

This is the first time a full live event has been shared online.(Scroll down to the May 28th, 2024 post.) Free link to videoSee...

The Best Outfits From “Love Island USA” Season 7 Reunion

While each product featured is independently selected by our editors, we may include paid promotion. If you buy something through our links, we may...

What To Buy From The Ulta 21 Days Of Beauty Sale 2025

With three whole weeks of epic beauty offers, there’s a lot to choose from. Luckily, our team of editors has combed through the entire...

Gas Station ‘Male Enhancement’ Pills May Work, but They’re Dangerous

I'm sure you've seen displays of "male enhancement"...