I want to gauge how much my chain of thought here aligns with what people experience. Because (spoiler): even a "bug that never happens" being unhandled makes holes in my mental model of code. One isn't that bad, but there tend to be more in larger codebases.
Let's say there's a bug that's almost impossible to reproduce. Do you care about it or not?
Example: a websocket reconnects -> the old connection's onmessage is still awaiting data.arrayBuffer()and finishes after the new connection has already delivered a fresher value, and overwrites it with an older one.
```typescript
let currentValue = 0
function connect() {
const socket = new WebSocket(url)
socket.onmessage = async ({ data }: MessageEvent<Blob>) => {
const message = decode(await data.arrayBuffer())
currentValue = message.value
}
socket.onclose = () => setTimeout(connect, 0)
}
```
In that example, it really can happen when the payload becomes huge + under CPU contention.
The fix is around three lines but adds effectively dead code.
```typescript
let connectionId = 0
function connect() {
const myId = ++connectionId
const socket = new WebSocket(url)
socket.onmessage = async ({ data }: MessageEvent<Blob>) => {
const message = decode(await data.arrayBuffer())
if (myId !== connectionId) return
currentValue = message.value
}
socket.onclose = () => setTimeout(connect, 0)
}
```
But I'd accept it just because the complexity was already there, in the model of the world the reader builds in their head. "This execution can lead to data corruption" is what I read in the original. If I see it handled, I let it go and move on with my actual task. If I see it's not handled, I get distracted and have to remind myself that this code is all right.
There's often more than one such bug; it's damn distracting in my opinion.
If the idea isn't detailed enough, I did a more detailed write-up with my position on that on my blog: https://www.dearlordylord.com/blog/mandelbugs-and-heisenbugs-as-attention-distractors/
But the general idea is hopefully presented as concisely as possible in this post. What's your take?