FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DLL Problems

 
Post new topic   Reply to topic     Forum Index -> DSP
View previous topic :: View next topic  
Author Message
pragma



Joined: 28 May 2004
Posts: 607
Location: Washington, DC

PostPosted: Fri Aug 20, 2004 1:18 pm    Post subject: DLL Problems Reply with quote

Basically a call to FreeLibrary, against a DMC/DMD built library causes stdin/stdout to stop working completely:

http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/1443

This probably has not been an issue for most folks since reloading a dll mid-application is a pretty rare thing to do. Also, most people over on the D news group seem to be more interested in using dll's for static linking rather than for dynamic use.

It took me a while to figure out why dll regeneration was causing my Mango server to quietly stop running altogether. It's really hard to find a bug that doesn't cause any exceptions to throw, or faults to attach my debugger to.

I cobbled the test server together from Kris' example in the standard Mango distribution. Well, the example code sets up a whole host of worker threads and then does this:

Code:

char wait;
Stdin >> wait;


The FreeLibrary bug causes stdin to simply stop working, much like it does with stdout. The last line here simply throws an error complaining that there's nothing left in the buffer, and falls through to the end of main(); this stops the server in a heartbeat.

This also explains why I never saw this during development of DSP V0.0A: Apache runs as a service so its not prey to problems like this. But this does explain why my debug output would suddenly dissapear after a bit.

I'm going to redo all my debug code to use file-based loggers instead, and see about doing something a little more clever for signaling a server shutdown. It needs to be done anyway to make a good robust server design.

- pragma
_________________
-- !Eric.t.Anderton at gmail
Back to top
View user's profile Send private message Yahoo Messenger
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Fri Aug 20, 2004 7:55 pm    Post subject: Re: DLL Problems Reply with quote

Ouch. That sounds like a really nasty problem to run into.

pragma wrote:
I cobbled the test server together from Kris' example in the standard Mango distribution. Well, the example code sets up a whole host of worker threads and then does this:

Code:

char wait;
Stdin >> wait;


Yeah; it's rather annoying that D doesn't have daemon threads. This was the only obvious way I could stop the primary thread from terminating, and thus the executable from exiting ... perhaps a call to sleep(forever) would be a better approach?

pragma wrote:
I'm going to redo all my debug code to use file-based loggers instead, and see about doing something a little more clever for signaling a server shutdown. It needs to be done anyway to make a good robust server design

Take a look at mango.log ~ it's modelled on Log4J and provides a few different kinds of logging plug-ins. You might find the RollingFileAppender to be just the ticket. Please let me know what you end up with for the shutdown issue?
Back to top
View user's profile Send private message
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Fri Aug 20, 2004 8:13 pm    Post subject: Reply with quote

I just traced the sleep() function on Win32, and it ends up in the SleepEx() NT function. This means you can do a usleep(uint.max) and the calling thread will be suspended for ever. I looked at the doc for usleep() on linux, but didn't see any note of infinite suspension akin to NT, so one may have to wrap a loop around the call:
Code:

while (true)
       sleep(uint.max);

Mango.io.System has a sleep() method in it, which I try to use. Perhaps I should add a sleepForever() method also? Or perhaps emulate the NT sleep-forever when uint.max is specified? Think I'll do the latter.

- Kris

(edit test)
Back to top
View user's profile Send private message
pragma



Joined: 28 May 2004
Posts: 607
Location: Washington, DC

PostPosted: Sat Aug 21, 2004 2:39 pm    Post subject: Re: DLL Problems Reply with quote

kris wrote:
Ouch. That sounds like a really nasty problem to run into.


You're telling me. I lost over a week to this bug. Judging by your posts on the bugs NG, you're having to navigate a similar minefield. I guess that's what we get for backing beta technology, eh?

I only hope my report gets catalogued along with all the other bugs in the NG. What suprised me the most is that this is a bug that's really in DMC *not* DMD... yet I couldn't find any evidence of it when searching around. I guess I'm looking at the intersection of some very rarely-done activities (Custom DllMain * DMC * Dll reloading = almost never)?

The hacker in me may wind up trying to build a bare-bones stub with MSVC and then use coff2omf to side-step the problem. Twisted Evil Symantec might also be another (and more compatible?) possibility.

kris wrote:

Yeah; it's rather annoying that D doesn't have daemon threads.

And later...
[quote ="kris"]
Mango.io.System has a sleep() method in it, which I try to use. Perhaps I should add a sleepForever() method also? Or perhaps emulate the NT sleep-forever when uint.max is specified? Think I'll do the latter.
[/quote]

kris wrote:

Please let me know what you end up with for the shutdown issue?


I'd advocate a combination of the two. IMO it's the sign of a well-built and mature library when you have formal, ready-to-use classes side-by-side with the really useful bits that help compose them. A sleepForever() method could have many applications, whereas a DaemonThread class would be only very useful for... well.. daemon threads. Smile

I have some ideas on how to sidestep not having stdin/out reliably. One of which is to have a telnet console for remote/external administration. Another would be to expose a method to shutdown the server internally from within a servlet (debug only of course). Both would require some event plumbing. We'll see.

kris wrote:

Take a look at mango.log ~ it's modelled on Log4J and provides a few different kinds of logging plug-ins. You might find the RollingFileAppender to be just the ticket.


I'll do just that... thanks for the tip!
_________________
-- !Eric.t.Anderton at gmail
Back to top
View user's profile Send private message Yahoo Messenger
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Sat Aug 21, 2004 3:26 pm    Post subject: Re: DLL Problems Reply with quote

Quote:
You're telling me. I lost over a week to this bug. Judging by your posts on the bugs NG, you're having to navigate a similar minefield. I guess that's what we get for backing beta technology, eh?

That's life in the sewer! Must be something wrong with us.

Quote:
I only hope my report gets catalogued along with all the other bugs in the NG. What suprised me the most is that this is a bug that's really in DMC *not* DMD... yet I couldn't find any evidence of it when searching around. I guess I'm looking at the intersection of some very rarely-done activities (Custom DllMain * DMC * Dll reloading = almost never)?

You're likely to be the first and, currently, only.

Quote:
A sleepForever() method could have many applications, whereas a DaemonThread class would be only very useful for... well.. daemon threads. Smile

True. But once a daemon is running, the executable should not exit (i.e. Java threads have a 'daemon' flag that's checked by the runtime). I imagine that the main thread actually calls sleep(forever) in such cases. Turns out to be equivalent I guess. System.sleep(uint.max) will now do the RightThing.

Quote:
I have some ideas on how to sidestep not having stdin/out reliably. One of which is to have a telnet console for remote/external administration.

Yep. You can use mango.log and hook it up to Chainsaw (an external Java event-viewer). The log can then be viewed both on- and off-line, remotely. You configure your server to use a SocketAppender & XmlLayout pair, and it hooks straight into Chainsaw (once the latter is configured). It's rather simple and quite cool! Even better: Mango.log has an Admin class that allows you to remotely (from a browser) control the type of log-output from your server, while the damn thing is operating ... works beautifully. So you can have remote logging via mango.log & Chainsaw, and remote configuration via mango.log.Admin. Take a look at the example.cserver for how to setup the latter, and example.logging for how to use the basic logging stuff. I'll guide you on how to setup Chainsaw if you like.

Quote:
Another would be to expose a method to shutdown the server internally from within a servlet (debug only of course). Both would require some event plumbing. We'll see.

Got you covered there also: you might use the mango.cluster package to multicast messages (topics) to your servers. One particular topic might be "eric.dsp.shutdown", causing an exit(). This is perhaps the simplest way to use the clustering package, and it really is very easy. I'll walk you through the process if you're interested. Perhaps I should write a brief example to demonstrate ...
Back to top
View user's profile Send private message
pragma



Joined: 28 May 2004
Posts: 607
Location: Washington, DC

PostPosted: Sat Aug 21, 2004 3:34 pm    Post subject: Re: DLL Problems Reply with quote

Awesome advice Kris. Thank you so much for all your generosity and help.

Looks like I've got some more learning and tinkering to do. I'll be in touch if I get lost in the woods on this one.
_________________
-- !Eric.t.Anderton at gmail
Back to top
View user's profile Send private message Yahoo Messenger
kris



Joined: 27 Mar 2004
Posts: 1494
Location: South Pacific

PostPosted: Sat Aug 21, 2004 4:49 pm    Post subject: Re: DLL Problems Reply with quote

pragma wrote:
Awesome advice Kris. Thank you so much for all your generosity and help

You're very welcome!

I have a feeling that you'll be getting a lot of unspoken thank-you's when DSP starts being used. The trouble with stuff like this is, it's actually quite rare to hear any feedback until there's a problem ... then you're sure to know all about it! These forums are no different in that respect. In fact, if you want to significantly increase the posts on this project, just introduce a bug or two ... Twisted Evil

N.B. I just checked in a Mango example called 'alert.d' showing how to use both send & recieve via the cluster. Also added a default argument to System.sleep() that will cause it to sleep forever.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DSP All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group