Threads and "blow out" 
Author Message
 Threads and "blow out"

I'm having a peculiar problem in a program...

I'm curious if anyone has ever had a program with behavior as such, or would
have any ideas as to what might cause it.

I have a multithreaded internet client, with assistance of MFC, and
everything [appears to] works fine.  Except, very rarely, people report the
program "randomly closing", without any dialog or error messages, and not
freeing resources.  It just no longer exists.
I haven't been able to reproduce the bug on one of my local dev boxes, but
at this point I'm confident that there's a bug in my code somewhere.
Like I said, the report is that the entire window just closes without a
trace, no dialogs, no error boxes..it just closes--as if an exit() was
randomly called in the middle of execution (of course, there is no such
thing)...any ideas?

I would really like to fix this problem.  Sorry I can't be more specific
about the problem, but, to be quite honest, I have no idea what is causing
it, or where to look.

So, if anyone has any ideas what could cause an app to "blow out" without a
trace, without freeing resources, I would greatly appreciate the assistance.

Thanks,
Rob



Sat, 25 Oct 2003 11:28:58 GMT  
 Threads and "blow out"
I am having the same exact problem with my server/client app.  I am using
the CSocket class along with a CWinthread derived class.  Upon the listening
socket accepting a connection I create a new thread object (suspended), pass
the handle of my socket to the thread to attach to its new socket and the
resume the thread.  The Dialog on the server end exits immediately.  When I
change the application to using a worker thread function instead of the
CWinthread derived object, everything works fine, very frusterating.  Let me
know if your setup is configured in a similar fashion.

-Darth


Quote:
> I'm having a peculiar problem in a program...

> I'm curious if anyone has ever had a program with behavior as such, or
would
> have any ideas as to what might cause it.

> I have a multithreaded internet client, with assistance of MFC, and
> everything [appears to] works fine.  Except, very rarely, people report
the
> program "randomly closing", without any dialog or error messages, and not
> freeing resources.  It just no longer exists.
> I haven't been able to reproduce the bug on one of my local dev boxes, but
> at this point I'm confident that there's a bug in my code somewhere.
> Like I said, the report is that the entire window just closes without a
> trace, no dialogs, no error boxes..it just closes--as if an exit() was
> randomly called in the middle of execution (of course, there is no such
> thing)...any ideas?

> I would really like to fix this problem.  Sorry I can't be more specific
> about the problem, but, to be quite honest, I have no idea what is causing
> it, or where to look.

> So, if anyone has any ideas what could cause an app to "blow out" without
a
> trace, without freeing resources, I would greatly appreciate the
assistance.

> Thanks,
> Rob



Sat, 25 Oct 2003 12:31:42 GMT  
 Threads and "blow out"
Have you gone through your program to ensure that all functions that could
return error indications are checked for errors and that all other possible
error conditions are being caught? Of course it is much easier for me to
suggest such a thing than it is to implement, but I hope that Windows is not
as vulnerable to problems such as that as it once was.


Quote:
> I'm having a peculiar problem in a program...

> I'm curious if anyone has ever had a program with behavior as such, or
would
> have any ideas as to what might cause it.

> I have a multithreaded internet client, with assistance of MFC, and
> everything [appears to] works fine.  Except, very rarely, people report
the
> program "randomly closing", without any dialog or error messages, and not
> freeing resources.  It just no longer exists.
> I haven't been able to reproduce the bug on one of my local dev boxes, but
> at this point I'm confident that there's a bug in my code somewhere.
> Like I said, the report is that the entire window just closes without a
> trace, no dialogs, no error boxes..it just closes--as if an exit() was
> randomly called in the middle of execution (of course, there is no such
> thing)...any ideas?

> I would really like to fix this problem.  Sorry I can't be more specific
> about the problem, but, to be quite honest, I have no idea what is causing
> it, or where to look.

> So, if anyone has any ideas what could cause an app to "blow out" without
a
> trace, without freeing resources, I would greatly appreciate the
assistance.

> Thanks,
> Rob



Sat, 25 Oct 2003 13:32:55 GMT  
 Threads and "blow out"
The problem occurs right as I call ResumeThread() on my CWinthread derived
object.  It is virtually impossible to debug at this point from my code
without digging into MFC, as my Init function for the thread is not reached.
I am fairly careful with exception handling for my CSocket classes and use
of CArchive and CSocketFile objects, and everything appears as normal up to
the point I indicated above.  Do you use CWinThread derived objects to
handle connections on your server as well?


Quote:
> Have you gone through your program to ensure that all functions that could
> return error indications are checked for errors and that all other
possible
> error conditions are being caught? Of course it is much easier for me to
> suggest such a thing than it is to implement, but I hope that Windows is
not
> as vulnerable to problems such as that as it once was.



> > I'm having a peculiar problem in a program...

> > I'm curious if anyone has ever had a program with behavior as such, or
> would
> > have any ideas as to what might cause it.

> > I have a multithreaded internet client, with assistance of MFC, and
> > everything [appears to] works fine.  Except, very rarely, people report
> the
> > program "randomly closing", without any dialog or error messages, and
not
> > freeing resources.  It just no longer exists.
> > I haven't been able to reproduce the bug on one of my local dev boxes,
but
> > at this point I'm confident that there's a bug in my code somewhere.
> > Like I said, the report is that the entire window just closes without a
> > trace, no dialogs, no error boxes..it just closes--as if an exit() was
> > randomly called in the middle of execution (of course, there is no such
> > thing)...any ideas?

> > I would really like to fix this problem.  Sorry I can't be more specific
> > about the problem, but, to be quite honest, I have no idea what is
causing
> > it, or where to look.

> > So, if anyone has any ideas what could cause an app to "blow out"
without
> a
> > trace, without freeing resources, I would greatly appreciate the
> assistance.

> > Thanks,
> > Rob



Sat, 25 Oct 2003 13:55:11 GMT  
 Threads and "blow out"

Quote:
> I'm having a peculiar problem in a program...

> I'm curious if anyone has ever had a program with behavior as such,
or would
> have any ideas as to what might cause it.

> I have a multithreaded internet client, with assistance of MFC, and
> everything [appears to] works fine.  Except, very rarely, people
report the
> program "randomly closing", without any dialog or error messages,
and not
> freeing resources.  It just no longer exists.
> I haven't been able to reproduce the bug on one of my local dev
boxes, but
> at this point I'm confident that there's a bug in my code somewhere.
> Like I said, the report is that the entire window just closes
without a
> trace, no dialogs, no error boxes..it just closes--as if an exit()
was
> randomly called in the middle of execution (of course, there is no
such
> thing)...any ideas?

> I would really like to fix this problem.  Sorry I can't be more
specific
> about the problem, but, to be quite honest, I have no idea what is
causing
> it, or where to look.

> So, if anyone has any ideas what could cause an app to "blow out"
without a
> trace, without freeing resources, I would greatly appreciate the

assistance.

Sounds strange. Sudden disappearing of process can be observed when
access violation exception is raised while the thread is attempting to
access the stack. However, you should be notified first via stack
overflow exception.

Check whether at some point there is try-catch(...) block, so all
exceptions are suppressed.



Sat, 25 Oct 2003 15:12:13 GMT  
 Threads and "blow out"
Where did I imply a suggestion to debug the program? I did not intend to.



Quote:
> The problem occurs right as I call ResumeThread() on my CWinthread derived
> object.  It is virtually impossible to debug at this point from my code
> without digging into MFC, as my Init function for the thread is not
reached.
> I am fairly careful with exception handling for my CSocket classes and use
> of CArchive and CSocketFile objects, and everything appears as normal up
to
> the point I indicated above.  Do you use CWinThread derived objects to
> handle connections on your server as well?



> > Have you gone through your program to ensure that all functions that
could
> > return error indications are checked for errors and that all other
> possible
> > error conditions are being caught? Of course it is much easier for me to
> > suggest such a thing than it is to implement, but I hope that Windows is
> not
> > as vulnerable to problems such as that as it once was.



> > > I'm having a peculiar problem in a program...

> > > I'm curious if anyone has ever had a program with behavior as such, or
> > would
> > > have any ideas as to what might cause it.

> > > I have a multithreaded internet client, with assistance of MFC, and
> > > everything [appears to] works fine.  Except, very rarely, people
report
> > the
> > > program "randomly closing", without any dialog or error messages, and
> not
> > > freeing resources.  It just no longer exists.
> > > I haven't been able to reproduce the bug on one of my local dev boxes,
> but
> > > at this point I'm confident that there's a bug in my code somewhere.
> > > Like I said, the report is that the entire window just closes without
a
> > > trace, no dialogs, no error boxes..it just closes--as if an exit() was
> > > randomly called in the middle of execution (of course, there is no
such
> > > thing)...any ideas?

> > > I would really like to fix this problem.  Sorry I can't be more
specific

> > > about the problem, but, to be quite honest, I have no idea what is
> causing
> > > it, or where to look.

> > > So, if anyone has any ideas what could cause an app to "blow out"
> without
> > a
> > > trace, without freeing resources, I would greatly appreciate the
> > assistance.

> > > Thanks,
> > > Rob



Sat, 25 Oct 2003 14:48:37 GMT  
 Threads and "blow out"

Quote:
> Sounds strange. Sudden disappearing of process can be observed when
> access violation exception is raised while the thread is attempting to
> access the stack. However, you should be notified first via stack
> overflow exception.

If any exception condition occurs and insufficient stack space exists to
dispatch the exception, then the thread is forcibly terminated. There is no
message box popup, and the user-mode de{*filter*} is not invoked. The thread
just "goes away". If it is the only thread in the process, then the process
will mysteriously disappear.

As you can imagine, this is a real pain to debug...

KM



Sat, 25 Oct 2003 15:28:03 GMT  
 Threads and "blow out"
On Tue, 08 May 2001 07:28:03 GMT, "keithmo"

Quote:

>If any exception condition occurs and insufficient stack space exists to
>dispatch the exception, then the thread is forcibly terminated. There is no
>message box popup, and the user-mode de{*filter*} is not invoked. The thread
>just "goes away". If it is the only thread in the process, then the process
>will mysteriously disappear.

Keith, I had not previously heard of this.  Can you provide any
references for further reading?

Jon



Sat, 25 Oct 2003 22:09:01 GMT  
 Threads and "blow out"

Quote:
> >If any exception condition occurs and insufficient stack space exists to
> >dispatch the exception, then the thread is forcibly terminated. There is
no
> >message box popup, and the user-mode de{*filter*} is not invoked. The thread
> >just "goes away". If it is the only thread in the process, then the
process
> >will mysteriously disappear.

> Keith, I had not previously heard of this.  Can you provide any
> references for further reading?

This is absolutely right. Windows stores the exception-handling frame on the
stack, and even the basic exception dialog is shown using this mechanism. If
you destroy the stack completely, Windows is unable to call either your
exception handler (if any) or the handler in kernel32.dll.

Try this program:

int main()
{
    char array[10];

    __try
    {
        memset(array, 'x', 5000);
        ((int*) 0) = 42;
    }
    __except(1)
    {
        printf("__except: should never get here\n");
    }

    printf("main: should never get here\n");
    return 0;

Quote:
}



Sat, 25 Oct 2003 22:22:41 GMT  
 Threads and "blow out"

Quote:
> ...
> I have a multithreaded internet client, with assistance of MFC, and
> everything [appears to] works fine.  Except, very rarely, people report
the
> program "randomly closing", without any dialog or error messages, and not
> freeing resources.  It just no longer exists.
> I haven't been able to reproduce the bug on one of my local dev boxes, but
> at this point I'm confident that there's a bug in my code somewhere.
> Like I said, the report is that the entire window just closes without a
> trace, no dialogs, no error boxes..it just closes--as if an exit() was
> randomly called in the middle of execution (of course, there is no such
> thing)...any ideas?
> ...

Do you have synchronization between your different threads? If two threads
try to access the same resources at the same time some unpredictable results
can occur. Also, make sure your main thread isn't closing for a reason or
another, this will close the child threads. I'm not familiar with the MFC
socket and thread classes, but I can tell you using API threads would be
much easier... Using winsock directly could eliminate some problems as
well.. MFC is just another layer on the Microsoft onion and the less layers
the more stable you'll get, and the closer you'll get to a profesionnal
result.

Alex.



Sat, 25 Oct 2003 22:25:28 GMT  
 Threads and "blow out"

Quote:

>From my experiences, if the main process thread exits, child threads aren't
>closed they are terminated right away.

Correct, and they continue to run while the main thread is destroying
static duration variables, uninitializing the CRT, etc. This is
something one normally needs to avoid.

--
Doug Harrison [VC++ MVP]
Eluent Software, LLC
http://www.eluent.com
Tools for Visual C++ and Windows



Tue, 28 Oct 2003 11:45:09 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. remove() vrs fopen("""w")

2. Displaying binary data as ascii "1"'s and "0"'s

3. Looking for "Shroud"/"Obfus"

4. ""help with TSR""

5. Parse trees and "("")"

6. Error "free"-ing "malloc"-ed memory

7. Displaying binary data as ascii "1"'s and "0"'s

8. strtok() is "thread unsafe?"

9. problem with "__declspec(thread)" in DLL

10. How to get rid of "Make-money-fast"-threads

11. Q: threads, sockets, "sink notification error"

12. Q: threads + socket = "sink notification error"?

 

 
Powered by phpBB® Forum Software