Works when I step through, doesn't work in real time
Hey guys, I'm working on making some network code that communicates through UDP. I've run into a strange problem though. One of my packets contains information about the size of an array to create. I was getting a system out of memory exception because it was reading some incredibly huge number instead of what it was supposed to be getting. So I go to step through my code and see where the problem is and it works fine when I step through it. Every time I step through it interprets and reads the data from the packets correctly. However, when I run the program normally without breakpoints, it reads incorrect data. I'm using C# and .Net. Any of you ever had a problem like this? Any ideas? I'll post more info if needed. Thanks!
What incredibly huge number do you get?
It sounds like if you run the app in realtime, the packet hasn't arrived by the time the recv() or recvfrom() call executes. If you run it in the debugger, the packet arrives while you're stepping through the code, so your recv() or recvfrom() succeeds.
It sounds like if you run the app in realtime, the packet hasn't arrived by the time the recv() or recvfrom() call executes. If you run it in the debugger, the packet arrives while you're stepping through the code, so your recv() or recvfrom() succeeds.
Well, it is receiving data in both situations because I only break when I break from running when I begin parsing received data.
If a bad packet (or mistakenly not reading a packet) can cause your app to allocate 'an unreasonably large amount of memory' shouldn't you apply some arbitrary-but-reasonable cap and return an error message if that cap is exceeded? Otherwise that leaves potential for malicious remote computers to kill your system by making your server allocate umpteen megahurtzes of gigabytes.
...Not that you're probably looking at things at that level at the moment, but just a thought. :)
...Not that you're probably looking at things at that level at the moment, but just a thought. :)
Yeah, well first I wanna find out why every time I run the program it crashes like this but every time I step through it works fine. I break the program when it begins the parsing process, so I don't really see what can be occurring differently between the two attempts.
Could you break if the number exceeds a reasonably large number? Then you may be able to trace through the call stack to see where things went wrong.
Then you should be able to catch the nasty situation.
My guess is it's some kind of race condition that doesn't occur when you are stepping through nice and slow. This is particularly common in threaded apps.
int allocation_size = parseThatPartOfThePacket();if (allocation_size > max_reasonable_number) int i = 0; // put a break point on this line
Then you should be able to catch the nasty situation.
My guess is it's some kind of race condition that doesn't occur when you are stepping through nice and slow. This is particularly common in threaded apps.
Quote:
Original post by fractoid
Otherwise that leaves potential for malicious remote computers to kill your system by making your server allocate umpteen megahurtzes of gigabytes.
Alternatively, he could be sure to buy a server that has more than an umpteen megahurtzes of gigabytes in RAM. ;)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement