Comment On Drowning in the Connection Pool

Today is one of those days were you're gonna think, that can't possibly be real ... no seriously ... it can't be! But it is; Chris F sure can attest to that. He found this while investigating connection pool exhaustion problems in an application he was unfortunate enough to inherit. The author, apparently, thought that converting a string (that oddly resembles valid code) to an integer would magically find the execution context and perform these calls on the appropriate objects. Worse still, it's only the tip of the iceberg ... [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Drowning in the Connection Pool

2005-06-06 13:20 • by the raven
I believe it's real ... there is no way anyone could make this up.

Re: Drowning in the Connection Pool

2005-06-06 13:24 • by Sean
I swear I worked with a guy that wrote code like this.

Re: Drowning in the Connection Pool

2005-06-06 13:29 • by Mike R
SQL Server 2000: $1850

Visual Studio 6: $750

1 Year MSDN Universal: $3500



Writing this line of "code:"



ReturnStatus = "sqlConnection" & CStr(connectionNum) & ".Close()"
Priceless.

Re: Drowning in the Connection Pool

2005-06-06 13:32 • by short
35625 in reply to 35622
Sean:
I swear I worked with a guy that wrote code like this.


i'm still working with one of those :)



Mike R, rotfl :D

Re: Drowning in the Connection Pool

2005-06-06 13:39 • by Anonymous
35626 in reply to 35625

short:
Sean:
I swear I worked with a guy that wrote code like this.

i'm still working with one of those :)

Mike R, rotfl :D


Who knows maybe you two are colleagues!

Re: Drowning in the Connection Pool

2005-06-06 13:44 • by christoofar
35628 in reply to 35626
I think people who have been found to be writing this type of code
should be blackballed from I/T, it (and consulting) give I/T workers a
bad reputation.



Ugh, I need a Percoset after looking at that.

Re: Drowning in the Connection Pool

2005-06-06 13:44 • by CrankyPants
35629 in reply to 35625

On Error Resume Next -- Helping bad VB progammers ignore their errors for 12 years.


I'm surprised it even compiled!  Is there no type checking in that compiler?

Re: Drowning in the Connection Pool

2005-06-06 13:48 • by Majromax
Okay... there's only one possible way that someone exhibiting such
utter stupidity can continue to breathe: he's used to scripting
languages.  In fact, he's so used to them, that his default state
is:



state = 'breathe()'

exec(state)

Re: Drowning in the Connection Pool

2005-06-06 13:53 • by spaceCode
35631 in reply to 35625
OMG ME TOO!



hahah





Re: Drowning in the Connection Pool

2005-06-06 13:53 • by christoofar
35632 in reply to 35629
Visual Basic programmers who use On Error Resume Next on everything are also found to have high incidents of:


  • Denial

  • Self-loathing

  • Keeping painful secrets from their loved ones

  • Fear of conflict (for being screamed at because some troll user saw a computer error)


Are you a Visual Basic programmer?  Are you experiencing any of
these symptoms?  Please call.  Don't hesitate, the future
of  your business software is at stake.



1-800-GET-HELP

Re: Drowning in the Connection Pool

2005-06-06 13:56 • by christoofar
35633 in reply to 35632
Public Function CloseConnection(ByVal connectionNum As Integer) As Integer

  On Error Resume Next

  Dim ReturnStatus As Integer

  ReturnStatus = "sqlConnection" & CStr(connectionNum) & ".Close()"



  If ReturnStatus <> 0 Then

    Return False  <----- WHAT THE FUCK THIS WONT EVEN COMPILE RETURN ISN'T A KEYWORD!!!!!

  End If



  Return True

  Exit Function

End Function



Re: Drowning in the Connection Pool

2005-06-06 13:57 • by PstScrpt
35634 in reply to 35629
Anonymous:

On Error Resume Next -- Helping bad VB progammers ignore their errors for 12 years.


I'm surprised it even compiled!  Is there no type checking in that compiler?



No, since version 4, VB has freely converted between integers and strings.  This is alternately referred to as "Implicit Type Conversion" and "Evil Type Conversion".  I take advantage of the shortcut, since I figure I've lost type safety, anyway. 


The string from the original post will always evaluate to 0.  Even if the "On Error" wasn't there, this function would always return success.

Re: Drowning in the Connection Pool

2005-06-06 13:58 • by nonDev
Alex Papadimoulis:

  Return True
  Exit Function
End Function




Exit function, exit function, exit function....

Re: Drowning in the Connection Pool

2005-06-06 13:59 • by christoofar
35636 in reply to 35633
OMG nevermind, this is VB.NET code.... oy vey brand new language, and now brand new WTFs to be generated every day.

Re: Drowning in the Connection Pool

2005-06-06 14:01 • by christoofar
35637 in reply to 35636
Now... how in the hell in VB.NET (assuming that since RETURN is only a
keyword in VB.NET).... can you possibly execute that sh** and expect it
to hit a method?   ?!?!?!!?

Re: Drowning in the Connection Pool

2005-06-06 14:01 • by PstScrpt
35638 in reply to 35636

christoofar:
OMG nevermind, this is VB.NET code.... oy vey brand new language, and now brand new WTFs to be generated every day.


VB.Net has "On Error..."?  I thought it was supposed to use try/catch/finally.

Re: Drowning in the Connection Pool

2005-06-06 14:03 • by christoofar
OMG nevermind this thing will never be able to execute anyway, starting
at the first line of executable code.  Look at what the type of
"ReturnStatus" is....

Re: Drowning in the Connection Pool

2005-06-06 14:23 • by lw
Ya know, this doesn't look so much like a coding error to me, but the
result of an automated merge that no one checked.  I'll bet half a
Coke that there was a line executing the string at some point, and the
merge mangled it.   ClearCase, anyone?

Re: Drowning in the Connection Pool

2005-06-06 14:25 • by JamesCurran
35642 in reply to 35630

Anonymous:
Okay... there's only one possible way that someone exhibiting such utter stupidity can continue to breathe: he's used to scripting languages. 


Further, I'd bet he came from a dBase -like language, where stuff like that actually worked!   (Since FoxPro is one such language, I wonder if that code would work there....)

Re: Drowning in the Connection Pool

2005-06-06 14:30 • by Richard
35643 in reply to 35630

Those two lines in particular remind of an application that was written with exactly that kind of code all the way through it, costing near to $1k. Can't name it unfortunately because the author might (though probably not) be reading this. :-)


 

Re: Drowning in the Connection Pool

2005-06-06 14:42 • by fregas
35645 in reply to 35621

At last.


At last we are bequeathed a WTF that harkens back to the days of old, when the glory of WTF was at its prime.  When code so putrid, so insepid, so utterly devoid of anything resembling logic, experience or basic programming rears its ugly head, causing us to shout in ardent disbelief: "WHAT THE FUCK!????"


And of course, its in Visual Basic...

I think I should update all of my code

2005-06-06 14:55 • by smitty_one_each

Exit Function
End Function
Because you never can be too sure the function will exit.

Re: Drowning in the Connection Pool

2005-06-06 15:07 • by Matt B
35649 in reply to 35638
PstScrpt:

VB.Net has "On Error..."?  I thought it was supposed to use try/catch/finally.







yay for backwards compatibility!!  

Re: Drowning in the Connection Pool

2005-06-06 15:08 • by whojoedaddy

So many things wrong with this small piece of code ... I can't even imagine what the rest is like...


 head hurts ... must lie down...

Re: Drowning in the Connection Pool

2005-06-06 15:10 • by rogthefrog
35651 in reply to 35621

Anonymous:
I believe it's real ... there is no way anyone could make this up.


Examples like this should be on a different site named thedailyOMG.com. Stunning.

Re: Drowning in the Connection Pool

2005-06-06 15:18 • by Im|tal
35653 in reply to 35626
Anonymous:

short:
Sean:
I swear I worked with a guy that wrote code like this.

i'm still working with one of those :)

Mike R, rotfl :D


Who knows maybe you two are colleagues!





excellent! *

Re: Drowning in the Connection Pool

2005-06-06 15:26 • by loneprogrammer
35655 in reply to 35641
Anonymous:
Ya know, this doesn't look so much like a coding error to me, but the
result of an automated merge that no one checked.


If no one checked it, why is it in the program?  You can't just
put junk in your code and expect the computer to know what you mean!



Re: Drowning in the Connection Pool

2005-06-06 15:28 • by strongarm

I love this...

  Return True      ' Return a true value.

Exit Function    ' But just in case that didn't work exit the function.
End Function       ' No, I really really mean it...

What happens if the End Function doesn't work? Shouldn't there be a fourth layer of redundancy in this method?



 

Re: Drowning in the Connection Pool

2005-06-06 15:32 • by PstScrpt
35658 in reply to 35656
strongarm:

I love this...

  Return True      ' Return a true value.

Exit Function    ' But just in case that didn't work exit the function.
End Function       ' No, I really really mean it...

What happens if the End Function doesn't work? Shouldn't there be a fourth layer of redundancy in this method?



 



Just to be picky, "End Function" isn't an executable statement.  It's like a closing curly bracket in C or Java.

Re: Drowning in the Connection Pool

2005-06-06 15:50 • by Richard Dudley

It's not bad enough that this is returning booleans as integers.  Then again, we couldn't expect Option Strict to be set to On.


If I ever needed an excuse to switch to C#, I now have one--to avoid being grouped with this example.

Re: Drowning in the Connection Pool

2005-06-06 15:57 • by rogthefrog
35661 in reply to 35660
In the car this morning I was wondering if VB had singlehandedly provided the world with the biggest number of WTFs, both in absolute terms and relatively to, say, the installed code base. This site seems to confirm my fear.

Re: Drowning in the Connection Pool

2005-06-06 16:16 • by strongarm
35663 in reply to 35658
PstScrpt:
strongarm:

I love this...

  Return True      ' Return a true value.

Exit Function    ' But just in case that didn't work exit the function.
End Function       ' No, I really really mean it...

What happens if the End Function doesn't work? Shouldn't there be a fourth layer of redundancy in this method?



 



Just to be picky, "End Function" isn't an executable statement.  It's like a closing curly bracket in C or Java.



Thanks for the reminder, I tried purging all VB knowledge a few years back, it appears I was more successful than I thought.


 

Re: Drowning in the Connection Pool

2005-06-06 16:44 • by John Bigboote
Most languages just give you enough rope to hang yourself.



VB without Option Strict allows you to implicitly convert everyday household objects into EVEN MORE rope.

Re: Drowning in the Connection Pool

2005-06-06 16:45 • by triso
35668 in reply to 35643
Anonymous:


...Can't name it unfortunately because the author might (though probably not) be reading this. :-)





Aw, c'mon, Richard. Name it! How about the initials? At that price and code quality, they should be out of business soon.

Re: Drowning in the Connection Pool

2005-06-06 17:00 • by Iam1967mustangman
1. Read post

2. Take off glasses

3. Clean glasses

4. Put glasses back on

5. Re-Read post

6. Resist urge to through myself in CNC in next building

Re: Drowning in the Connection Pool

2005-06-06 17:01 • by DjDanny
35670 in reply to 35638
PstScrpt:

christoofar:
OMG nevermind, this is VB.NET code.... oy vey brand new language, and now brand new WTFs to be generated every day.


VB.Net has "On Error..."?  I thought it was supposed to use try/catch/finally.



 


oh yes, it does have try/catch/finally, but you can't expect VB 'programmers' to give up their most useful command. Why write decent code, when you can just pretend it works fine all the time?!

Re: Drowning in the Connection Pool

2005-06-06 17:08 • by uber1024
35671 in reply to 35621
And he's only 1 line away from having code that does something useful, too.

Re: Drowning in the Connection Pool

2005-06-06 17:38 • by RayS
If only he were using vbscript instead of vb.net he'd have been oh so very close.

Just adding



Execute(ReturnStatus)



in the empty line would have done the job. Ah what a pity.





Actually, I wonder if it's possible that this could have been migrated
over from a vbscript, and the line above removed by a dimwitted
programmer in order to get it to compile without complaining. Worth a
thought.



Re: Drowning in the Connection Pool

2005-06-06 17:38 • by Jeff S

I almost missed the best part -- look at the argument of the function.  At first I thought he was passing in a reference to a connection object ... but, nope .... it's an integer -- the "connection number" !  The index to a global array of connection objects, you might think?  That would be bad enough, but again, no ... apparently he has the global variables "sqlConnection1", "sqlConnection2", etc all declared and opened in his application !  


And of course, since this code actually does NOTHING, and none of these ever get closed, that makes it all even worse. 


A true classic.


I'd love to see more of this code ... it's amazing how there's not even a shred of understanding about the most basic of programming concepts present in this code ...

Re: Drowning in the Connection Pool

2005-06-06 18:01 • by RayS
35676 in reply to 35670
Anonymous:
PstScrpt:

christoofar:
OMG nevermind, this is VB.NET code.... oy
vey brand new language, and now brand new WTFs to be generated every
day.


VB.Net has "On Error..."?  I thought it was supposed to use try/catch/finally.



 


oh yes, it does have try/catch/finally, but you can't expect VB
'programmers' to give up their most useful command. Why write decent
code, when you can just pretend it works fine all the time?!



Why do so many people have a problem with a tool which admittedly can
be abused, but not half as much as dozens of things in C++ and other
languages?


Let's look at an example - log all the attributes of a bunch of files in a directory as you try to move them elsewhere.


Try/Catch scenario psuedocode:

try (get list of files)

try (loop through files)

    try (log some file attributes)

    try (log some more attributes)

    try (log permissions)

    try (copy file)

    try (delete file)

end loop


Also remember that those 'try()'s expand into full Try/Catch
structures where essentially all you do is discard the error and carry
on.  Surely there's a better and quicker way to do that with the
same result?



Resume next scenario pseudocode:

on error resume next

get list of files

loop through files

    log all details

    copy file

    delete file

end loop


Now isn't that a hell of a lot easier? Yes. Any problems caused? Not
really, since we were discarding errors anyway. Before anyone moans
that I'm making more work in the Try/Catch case, remember how granular
NTFS permissions are. You may very well have permissions to some file
info but not something else. Resume next means not having to read and
discard errors for things like that.


It's not how you should do everything, but it has very valid
reasons, the above being just one and probably not one of the best
examples, either. Now, let's have less stupidity from elitist morons.


Re: Drowning in the Connection Pool

2005-06-06 18:18 • by Ken
Just one little change to the project would have prevented this from compiling - turn Strict On.  No VB.NET project should be without it!!  [;)]

Re: I think I should update all of my code

2005-06-06 18:29 • by mizhi
35678 in reply to 35647
smitty_one_each:

Exit Function
End Function
Because you never can be too sure the function will exit.




It's like C code I run into where the return type of the function is void.



void foo()

{

.

. miles of bad code

.

return;

}



Re: Drowning in the Connection Pool

2005-06-06 18:51 • by dmoisan

Way, way back in the day (circa 1979), on a DEC RSTS/E OS, returning a string to execute a system dispatch Was The Way Things Were Done, like:


A$=SYS(CHR$(13)+...)


IF A$="" THEN PRINT "SYSTEM CALL ERROR" ELSE...


Yes, RSTS used BASIC for system utilities.  Doubt that the author of the original code knew that, but it explains more about VB than I wanted to know:  Microsoft's original business was writing BASIC interpreters using DEC hardware to cross-compile.


 

Re: Drowning in the Connection Pool

2005-06-06 19:05 • by A Wizard A True Star

I'm pretty sure this is just code migrated from ASP to ASP.NET. There was probably a call to Exec() around the string. When they tried to compile it in .NET they saw the error "Name 'Exec' is not declared" and took out the Exec. Voila, it compiles!


Of course, it should have occurred to whoever took out the Exec that this function was no longer doing anything. Still, the variable naming is an even bigger WTF. Somewhere in that app, there's a set of global variables declared like:


Dim sqlConnection1


Dim sqlConnection2


Dim sqlConnection3


Dim sqlConnection4


Dim sqlConnection5


Dim sqlConnection6


...


Dim sqlConnection255


...


Yeah. We really need to see some more of this code.


 

Re: Drowning in the Connection Pool

2005-06-06 19:08 • by A Wizard A True Star
35682 in reply to 35681

Meant to say "Eval", not "Exec".


 

Re: Drowning in the Connection Pool

2005-06-06 19:39 • by Rank Amateur
35684 in reply to 35681
A Wizard A True Star:

I'm pretty sure this is just code migrated from ASP to ASP.NET. There was probably a call to Exec() around the string. When they tried to compile it in .NET they saw the error "Name 'Exec' is not declared" and took out the Exec. Voila, it compiles!


<Snip>



Plausible scenario, like the earlier theory that it came from VBScript, but what about the fact that ReturnStatus is declared as integer? Either in porting they changed it from string (WTF!), or it never worked in ASP to start with (WTF^2!). Right?


--RA

Re: Drowning in the Connection Pool

2005-06-06 19:44 • by Riken
35685 in reply to 35676
RayS:
Let's look at an example - log all the attributes of a bunch of files in a directory as you try to move them elsewhere.


Try/Catch scenario psuedocode:

try (get list of files)

try (loop through files)

    try (log some file attributes)

    try (log some more attributes)

    try (log permissions)

    try (copy file)

    try (delete file)

end loop


Also remember that those 'try()'s expand into full Try/Catch
structures where essentially all you do is discard the error and carry
on.


It's not how you should do everything, but it has very valid
reasons, the above being just one and probably not one of the best
examples, either. Now, let's have less stupidity from elitist morons.



WTF??? If I saw the above C code I would assume the programmer is a stupid VB coder.



Lets analyse your example.



try (get list of files) --- if this fails, we shouldn't loop

try (loop through files) --- why would this fail? oh yes because we didn't check the error on the previous line

    try (log stuff) --- Hmmm, logging didn't work, we'll ignore it

    try (copy file) --- Hmmm, copy didn't work, we'll ignore it

    try (delete file) --- But the delete did work, so now we have no log, no copy, no original and no explanation

end loop



Gee you're right, bad programmers can write bad code in any language.

Re: Drowning in the Connection Pool

2005-06-06 19:46 • by Schol-R-LEA
*vomit*

Re: Drowning in the Connection Pool

2005-06-06 20:56 • by Jon Limjap
35688 in reply to 35636
christoofar:
OMG nevermind, this is VB.NET code.... oy vey
brand new language, and now brand new WTFs to be generated every day.




It's not VB.NET, mind you. It's Visual Basic 6.

Re: Drowning in the Connection Pool

2005-06-06 21:01 • by Alex Papadimoulis
35689 in reply to 35688

Jon Limjap:
christoofar:
OMG nevermind, this is VB.NET code.... oy vey brand new language, and now brand new WTFs to be generated every day.


It's not VB.NET, mind you. It's Visual Basic 6.


Sadly .. it actually is VB.NET ... I have another example from this project I'll be posting sometime later. One tell-tale sign is the use of the Return keyword. VB6 does not support it.

« PrevPage 1 | Page 2 | Page 3Next »

Add Comment