Delphi XE8 gracefully handle ETetheringException at application startup - delphi

The Delphi app tethering manager reserves 20 ports in the range from 2020-2039 to start up its communication threads.
I wanted to find out what happens, when the 21st application is started on the same computer. It turns out that this application just hangs unresponsive until it is killed and I haven't found a way to terminate it gracefully.
To reproduce, just drop a TTetheringManager and a TTetheringProfile on an empty form, connect the profile to the Manager, compile, start the application 20 times outside the IDE and finally start the 21st instance in the IDE.
This is what I have found out so far:
In System.Tether.NetworkAdapter: procedure TTetheringNetworkManagerCommunicationThread.Execute;
an ETetheringException.Create(SManagerNetworkCreation) is raised when either the TCP or the UDP communication server could not be started. So far so good.
This exception shows up in the Debugger. When I continue and step through the following code, the application finally hangs in System: function AcquireExceptionObject and never returns.
Since the application is raised during Application.Run, I tried to catch the Exception via:
try
Application.Run;
except
ShowMessage('Something went terribly wrong!');
end;
but this didn't work. Any suggestions how I can catch (or prevent) this exception?

Since this really seems to be a bug, I filed a quality report for it: https://quality.embarcadero.com/browse/RSP-11345

Related

Connecting to local server via dBExpress

My D7 dBExpress project is supposed to connect to a local Interbase XE7 server.
It has the usual DBX setup: SqlConnection, SqlQuery, DataSetProvider and
ClientDataSet and does a simple 'select * from mytable'.
Last time I used it, it was working fine, but today when I ran it inside the IDE,
I get an exception as I call
ClientDataSet1.Open;
in my FormCreate (that call is the entire code of the project, btw). The
exception is an EDatabaseError with msg "No mapping for Error Code Found." and happens in TSqlConnection.DoConnect
That sounds familiar - I got that error myself one time, when I went back to an IB project after a few weeks.
It turned out that in the meantime something had sneaked Firebird onto my machine and it had hijacked the port IB usually listens on, and it was actually this FB server which was rejecting the connection, not the Interbase one!
Take a look under Services to see whether there is an FB server running. If there are, close it down (and start the IB server if not already running, of course). Then try your DBX project again.
Somewhere in the IB docs, I found something which seemed to suggest there was a way of getting FB and IB servers to coexist, but to avoid falling into a similar trap another time, I wrote a couple of batch files to shut down one of them and start the other. One is called "UseIB" and contains:
net stop "Firebird server - DefaultInstance"
net start "InterBase XE7 Server gds_db"
The other one, "UseFB" just does the opposite, of course.

"<Program> has stopped working" explanation

Can someone explain me when Windows shows this message?
What do i have to do to stop my Program from throwing this exception?
I have a Delphi Windows Forms Program which throws this message short after doing some SQL operations.
So i do the SQL, everything seems fine at first, but at a random time after that windows is killing it by showing this message...
the intresting thing is, it only occours while debugging.
When i'm not debugging it's running perfectly stable.
EDIT: Using RAD-Studio2009
I dont want to turn off the message completely(Only hint i found by using Google)
i want to stop my program giving windows a Reason to do that.
Windows shows this message when an unhandled exception leaks out of your application. This is a fatal condition. Something very wrong has happened with your application because exceptions should all be caught.
You need to work out what is throwing the exception and why it is not being caught. The very first step is to expand the details of the error dialog and find out which module the fault is occurring in, what the fault is and so on. That should yield some high level clues at the very least.
Most likely the Delphi debugger will not be able to help you for such a fault. You need to configure your system to arrange for a crash dump to be produced by the Windows Error Reporting service. Then you can load up the error report in a tool like WinDbg and try to figure it out.

Trouble getting windows service to start

I'm having trouble getting a windows service to start. Each time it runs, in the IDE, as a service, or otherwise, an error shows up in the windows event log stating:
"The service process could not connect to the service controller."
When debugging, I can step through the ServiceCreate procedure, and I successful print to a log file there. However, I have identical code (save the message string) in the ServiceStart or ServiceExecute procedures and it never appears to run.
The debugger lets me step into Application.CreateForm, which jumps straight to the ServiceCreate procedure but I cannot step into Application.Run.
Any ideas?
Edit: To clarify, I am debugging by starting the windows service, then attaching to the process in Delphi during a wait that I added to start up.
Edit 2: Okay, it's now letting me step into Application.Run and more details where ever I want. I had turned off debug dcus. Thought stepping through the VCL code did nothing to help me see what the problem was. I still have no idea how ServiceStart or ServiceExecute are supposed to get called.
this is the only error message you receive? what code do you have in the initialization section of your pas files? this error is generally raised when an error is raised and your application doesn't catch it. try to log all the events from app. also, take a look into the Windows event viewer for more details related to this.

Service Not Responding - Error 1053

The program starts correctly if I double-click it or if I debug it from VS2010, but it doesn't respond when I try running it from Services.msc. It used to work just fine, but I tried to un-register and then re-register the service to fix a different bug and now I get the following error:
Could not start the PFAdapterMng service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion.
I tried putting logs at the beginning of main(), and I found out that the service stops responding before it even gets there.
I've tried using Procmon to figure out if there's some registry key missing, but I couldn't find any problems through Procmon.
I've also tried re-registering the service to try to fix it, since re-registering the service was what caused the error in the first place. It doesn't seem to fix anything either.
I've stepped through the program with the parameters -UnregServer and -Service to ensure that the program was being unregistered and registered successfully, and it looks like it's being registered as a service correctly.
Is this because of some error in the registry? I don't see how or why my program stops responding before it even gets to main().
What else could I try to do to debug this problem?
UPDATE:
So, I tried un-registering the service after trying to run it, and it seemed to work fine. I look in services.msc, and I still see that the application is a service. In the past, before I got error 1053, it would just disappear after the first time. I tried un-registering it again, and I got a message box:
Service could not be deleted
So I decided to run the application with the parameter -UnregServer inside of Visual Studio 2010 to figure out what the error is. The function DeleteService() is failing with the error:
ERROR_SERVICE_MARKED_FOR_DELETE
The service is not removed until all open handles to the service have been closed. I stepped through the calls to the CloseServiceHandle() function and it seems like the handles were closed successfully. The service is also not removed if the service is running. I checked Process Manager, and the service was not running. Is the service not being removed because the service stopped responding earlier?
I tried restarting my computer and it was gone. Still, I don't understand why I have to restart my computer when the service used to un-register without the need of a restart before I was getting error 1053. Unless of course I can't un-register the service because the service was not stopped because it stopped responding.
I'll keep trying some more things, but I'm running out of ideas.
UPDATE2:
I tried rebuilding the original application, which I know worked as a service. This means the problem is not related to any of my code. Something is messed up with the Services Control Manager. I don't understand why I only get this error with this application. I have another application which communicates with this application which also needs to be registered as a service. I have no problems with that application. It works perfectly.
But for some reason, this application just stopped responding all of a sudden. I don't know what I changed or broke to cause the service to hang before it even gets to my main() function. The only thing I can think of now to fix the problem is to reformat the server, which is not an option.
Thanks,
Krzys
I feel stupid.
I've been using Remote Desktop Connection to connect to this server. Well, the service is starting and erroring out. The reason I didn't see any errors or message boxes was because they were appearing on the console session. I was not connected to the console session. I connected to the server using:
mstsc.exe /admin
And now I can see where the program stops responding.
Feels great to waste 10 hours though.

Debugging Delphi ISAPI Dll on Apache

I have run into a situtation where frequently when debugging a ISAPI Dll (TWebModule) running under Apache I get errors. The caption on the error box is "Debugger Fault Notification" and contained in the message is, among other things:
"c:\program files\Apache\bin\httpd.exe faulted with message......."
When this happens the cpu window pops up, and I have to hit the "OK" button on the error message. I might have to do this 3 - 5 times before program flow continues.
This is happening on my laptop. I have a desktop with the same exact configuration (as far as I know) and I don't have this problem. Both operating systems are XP. So obviously there is some setting or outdated file somewhere.
Also, I have noticed if first run my website when Apache is not in the debugging envrironment it seems not to have this problem. (i.e. start apache in the services, run my web app, stop the service, and then debug it within the Delphi environment).
Any ideas???
While it doesn't directly answer the how to debug using Apache, another alternate debugging technique which works well is to use idDebugger (near the bottom of that page). It will allow you to debug ISAPI DLL's directly from the IDE without having to start/stop services. I now never develop ISAPI DLL's without it.
To avoid this and other problems, I've started xxm. It's an alternative to TWebModule, and uses a separate wrapper to run with IIS, but there's also an Apache, FireFox and IE wrapper! It also uses mixed-HTML-Delphi-source and the development-mode wrappers do the parsing and an auto-compile to give a web-script-like environment.
Also the InternetExplorer plugin works great in the debugger (with iexplore.exe as host application).
Error code 0xC0000008 is Status_Invalid_Handle. That can be thrown by CloseHandle, for example, when you try to close a handle that either was never open or was already closed. The error might not occur when you're running outside the debugger because the API won't throw an exception unless it's being debugged.
If you're getting that exception in code that the debugger doesn't have access to, then the debugger will display the CPU window instead. Look at the call stack to find the place in your code closest to where the exception came from.
It's also possible that it's not occurring in your code at all. Try doing your same debug routine without your module installed. Do you still get errors?

Resources