Eye Training · Resources and Cleanup
Everything you open, take or start must be given back on every path out: success, early return, thrown error and shutdown.
Part 2 · Surface 24. Bug counts are hidden and some snippets are clean. See Start Here for how to use these drills.
J · The basics
Bug hunt
J · Sync button
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min
Bug hunt
J · Find a user
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min
Bug hunt
J · Find an order
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min
M · Three years in, these should jump out
Bug hunt
M · Image preview
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min
Bug hunt
M · PDF conversion
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 2 min
Bug hunt
M · Cache sweeper
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 2 min
Bug hunt
M · Thumbnails
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 2 min
S · Where seniors stand out
Bug hunt
S · Transfer
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 2 min
Bug hunt
S · Shutdown
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 2 min
Bug hunt
S · Compress a log
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min
What your eye checks
Whenever code opens, takes or starts something, find where it's given back, then ask:
- Is it released on every path? Early returns and thrown errors skip the last line. Releases belong in
finally. - Does a flag or lock get reset on failure? A stuck
busyis a resource leak too. - Is a transaction rolled back? Releasing a connection isn't enough if the transaction is still open.
- Is there a limit? Threads, connections, child processes and open files need a pool or a cap.
- Does importing it start anything? Timers and sockets started at import time keep the process alive.
- Are names unique? Temp files and keys built from
Date.now()collide. - Does shutdown wait? Stop taking work, finish what's in flight, then close what it uses.
- Is there a helper that does the cleanup for you?
pool.query,pipeline,fs.rmwithforce.
Tells
| You see | Ask |
|---|---|
pool.connect() | Where's release, and is it in finally? |
return between acquire and release | Released on this path? |
busy = true … busy = false | What if it throws in between? |
BEGIN without a ROLLBACK | What does the next user of this connection get? |
URL.createObjectURL | Where's revokeObjectURL? |
new Worker, spawn, new Client per request | What's the limit? |
setInterval at the top of a module | Does the process ever exit? |
tmpdir() + Date.now() | Unique? Deleted on failure? |
server.close() not awaited | Are requests in flight dropped? |
Go deeper
- try / catch / finally: which failures escape and what
finallyguarantees - Streams and streaming data: backpressure and stream errors
- Previous surface: Time and dates · Next: Node servers (not written yet)