close()

“Hey,” I say, knocking on a programmer’s office door. “You have a second?”

“What? I’m in the middle of something.”

“Me, too. Another production outage, in fact. I’ve been helping some folks figure out why we’re having database connection problems. All their database connections are being used up. Turns out it’s the web application you rolled out last week. Did you get my email yesterday?”

“Yeah.”

“So did you have any thoughts on it?”

“The DBAs just need to increase the number of database connections allowed.”

“Well, that’s what they did to work around this. Does your web application really need 300 open connections to the database?”

“It opens what it needs,” he says in a snotty tone of voice. “That’s what the connection pools are for, you know. They manage that.”

“I know. Actually, I looked at your code and nowhere do you close a database connection when you’re done, which would release the connection back to the pool. So every time a user connects we get another connection, leaked out.”

“Who gave you a copy of my code? That’s mine, you know, and you can’t just go messing around with it.”

“I’m your sysadmin. Plus when it started causing production outages and you were nowhere to be found your boss gave us permission.” Besides, the code belongs to the organization, not that we’d actually want it.

“The operating system will clean all that up when the application exits. First year CS students even know that.”

“Actually, when I was a first year CS student they taught me that every open() should have a corresponding close(). Plus, the OS will only clean things up that actually terminate. Persistent stuff like these web applications don’t terminate completely, hence the ‘persistent’ part, so if you don’t release the resources you used they leak.” Welcome to 1996, though this isn’t always true, depending on the environment. It just happens to be true for this.

“Well, I’m busy here with another problem and can’t help you. Just go explain to those DBAs that they should read the manual for their fancy software.”

“Nah, the only thing I’m going to explain is this conversation to our bosses.”

3 thoughts on “close()”

  1. Thanks for this post. I’ve always found that the best programmers I’ve worked with (as a sysadmin and as a developer) are the ones who are never satisfied with their code, and continually improve upon their work… Perhaps this guy will learn that one day.

Comments are closed.