Problem: apache plugin initialises C++ statics twice

T

tropos

I work on a large Apache plugin for an Internet Bank. Logging shows
that many or all static objects in the plugin are being initialised
twice at startup time.

The platform is C++, AIX Unix, using the vaccp compiler. The plugin is
built as a shared object (.so) file.

My first thought was that Apache's parent process loads the shared
object and initialises it, and then it forks to a child process which
does the same. But the logging gives the same PID for both
initialisations of each of the static objects. It appears to occur in
the child process.

Running the same classes in a test harness (not a plugin) shows normal
behaviour. The problem appears to be related to the Apache
environment.

Can anyone explain this?

tropos
 
P

Phil Endecott

tropos said:
I work on a large Apache plugin for an Internet Bank. Logging shows
that many or all static objects in the plugin are being initialised
twice at startup time.

I believe this is a known feature of the way Apache loads modules; it's
something like it loads it once to see if it will load without error,
and then loads it again "for real". In my apache module code, I have a
comment something like this which I added when I discovered this behaviour:

// This gets executed approximately once when the module is loaded

Note the word "approximately" in there.

I think you need to work around it by (a) not having anything
substantial in statics, and/or (b) accepting a certain amount of
leakage. I would avoid static objects in dynamically loaded code in any
case; I'm not sure about current compilers, but in the past I would have
worried about whether they are executed at all.

Anyway, the Apache mailing lists are the right place to ask about this;
expect to get a few "OFF TOPIC HERE" replies from this group's regulars....


Phil.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,973
Members
47,529
Latest member
JaclynShum

Latest Threads

Top