A rookie mistake

A rookie mistake

Consider the following function :

Can you spot the error in this function?

It makes the rookie mistake of assuming that `sleep()` is reliable. The call to `TimeUnit.SECONDS.sleep(1)` will certainly put the thread to sleep for a second, that much we can rely upon. The problem is that the sleep can extend to beyond one second; perhaps 2 seconds on an autumn day and perhaps 5 seconds on a full moon night.

Essentially, there are no guarantees that the duration of sleep will be exact or even within a tolerance. This makes the `checkTimeOut` a lower bound at best and a long lasting siesta at worst.

A recent incident at work was traced in part to a function that, in essence, made the same mistake. It ran fine for eight months in production before failing. Since I was on support during this incident and helped diagnose the root cause, I naturally went back to see who wrote the code and when.

No prizes for guessing who it was ???

(Cross-posted from my blog)

Gautam Patwardhan

Director - Supply Chain & Operations

9 年

So true!

回复

要查看或添加评论,请登录

Deepak Sarda的更多文章

  • The Paradox of Choice

    The Paradox of Choice

    I read an insightful article today addressing the paradox of choice many people encounter when starting to invest. I…

  • Don’t ignore Chaos testing!

    Don’t ignore Chaos testing!

    In my previous role, I led the product development & delivery of observability services. This included passive…

    2 条评论
  • A curious bug

    A curious bug

    I spent some time yesterday debugging a very curious bug. One of the apps that my team maintains is a lightweight HTTP…

社区洞察

其他会员也浏览了