DevDisasters

Reverse Psychology

Everything at Henry's company revolved around contracts with vendors. The IT department had relied on the aptly named Contract Manager -- the sole remaining Visual Basic 6 client-server application -- to support that business for the past 12 years.

Contract Manager was a rotten apple in the IT department's orchard of .NET Web apps. Its picky nature kept the company one release behind the latest Windows version, just to be on the safe side. The system's logic was inefficient and tangled, making it a pain to develop and maintain.

The only reason anyone could figure it was still around was because, though old, Contract Manager rarely broke. Rest assured, though, on those rare occurrences when it did break, people noticed.

Break Big or Not at All
"The Contract Manager is crashing!" yelled a voice on the phone. "We can't add new contracts into the system! This is really critical!"

Henry was jarred upright. He wasn't used to these kinds of calls.

"Um, OK. Well, are you getting any error messages?" Henry stammered, but it was of no use -- the line was already dead. Call after call came in and played out the same way.

One user, who followed up with an e-mail after Henry ignored her phone calls, was kind enough to include a screenshot of the error, which pointed to a culprit:

 Integer Overflow on N_CONTRACT_ID.

Henry gulped.

He knew that in Visual Basic 6, integers overflow at 32,768. Could it be that users had managed to exhaust all of the possible Contract ID numbers? Henry quickly checked to confirm his suspicions and sure enough: the 32,768th contract was entered earlier that morning.

Henry knew he could easily fix the code to accept larger IDs, but there was a catch. The Contract Manager .EXE was compiled against a COM+ DLL. This meant Henry had a choice. Fix the COM+ DLL to allow for larger Contract IDs, recompile the client, and force everyone to upgrade the right way (and take forever) … or he could hack it.

Strike That -- Reverse It
Henry had a bold idea. While he was out of positive ID numbers, there were plenty of negative ones. He turned the sequence that generated Contract IDs around, so that it started at -1 and counted down, but that created a new problem.

Contract Manager had huge amounts of business logic in the database, and that meant that it was scattered in dozens of procedures, packages and views. The code to fetch the latest contract resembled the following:

WHERE q.n_contract_id = 
  (SELECT MAX(n_contract_id) FROM contract_rev cr WHERE cr.n_bid = q.n_bid)

So, Henry brute-forced it and replaced all of the SELECT MAXs with this code:

SELECT CASE
  WHEN MIN(n_contract_id) < 0 THEN MIN(n_contract_id)
  ELSE MAX(n_contract_id)
END CASE

Terrible, kludgy and awful, but in the end, it worked! Henry had squeezed another decade out of Contract Manager. He just hoped the system wouldn't be around that long.

About the Author

Mark Bowytz is a contributor to the popular Web site The Daily WTF. He has more than a decade of IT experience and is currently a systems analyst for PPG Industries.

comments powered by Disqus

Featured

  • Xamarin.Forms 5 Preview Ships Ahead of .NET 6 Transition to MAUI

    Microsoft shipped a pre-release version of Xamarin.Forms 5 ahead of a planned transition to MAUI, which will take over beginning with the release of .NET 6 in November 2021.

  • ML.NET Improves Object Detection

    Microsoft improved the object detection capabilities of its ML.NET machine learning framework for .NET developers, adding the ability to train custom models with Model Builder in Visual Studio.

  • More Improvements for VS Code's New Python Language Server

    Microsoft announced more improvements for the new Python language server for Visual Studio Code, Pylance, specializing in rich type information.

  • Death of the Dev Machine?

    Here's a takeaway from this week's Ignite 2020 event: An advanced Azure cloud portends the death of the traditional, high-powered dev machine packed with computing, memory and storage components.

  • COVID-19 Is Ignite 2020's Elephant in the Room: 'Frankly, It Sucks'

    As in all things of our new reality, there was no escaping the drastic changes in routine caused by the COVID-19 pandemic during Microsoft's big Ignite 2020 developer/IT pro conference, this week shifted to an online-only event after drawing tens of thousands of in-person attendees in years past.

Upcoming Events