Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WebSnap + Apache2 + multithread BUG ?

10 views
Skip to first unread message

Paulo

unread,
Aug 22, 2003, 6:11:04 AM8/22/03
to
Hi All,

I have some strange errors when more than 1 client is rendering the page at
a time. It's some kind of problem with threads + ActiveScripting interface
(error occurs when two threads are executing JScript at exact one moment).
It is very easy to reproduce:
1. Build Apache DSO WebSnap app - just from the wizard
2. Put a script which takes a lot of time to render
example:
<html>
<body>
<% for (i = 0; i < 10000; i++)
Response.Write(i);
%>
</body>
</html>
3. Write a static page like this:
<HTML>
<FRAMESET ROWS="10%, 10%, 10%, 10%, 60%">
<FRAME src="page's URL here">
<FRAME src="page's URL here">
<FRAME src="page's URL here">
<FRAME src="page's URL here">
<FRAME src="page's URL here">
</FRAMESET>
</HTML>

When you display the frameset 5 copies of the page are rendered at a time.
The result is that one or more pages display a random error message like:
"List index out of bounds"
"Wrong number of parameters for WriteItem" etc.
The number of error pages increases on two-processor machine so thread
concurrency must be involved in this issue.
The error occurs whenever you access scripting objects from within the
script. If the page doesn't contain any references to scripting objects
there is no error.
The only scripting object which looks "safe" is WebSnap inner HTML_ object
used for html content rendering. Even read of properties like
Application.Title inside loop causes random errors.
The only solution I've made so far is rendering the pages in critical
section - so no more than one thread can render a page at a time, but I
worry about the performance. I won't take advantage from my two-processor
server any more :(

Any ideas ? Clues ? Solutions ?
After many hours of websnap debugging I'm desperate.

Hope for help

Paweł Kowalik


Robert

unread,
Aug 25, 2003, 4:46:47 AM8/25/03
to
hi

i also had a problem with the "script engine"

i was using CoInitialize();

i replaced it with
CoInitializeEx(nil,COINIT_MULTITHREADED);

(not sure if this help's)

robert


"Paulo" <p.ko...@gazeta.pl> schrieb im Newsbeitrag
news:3f45ebfa$1...@newsgroups.borland.com...

Paulo

unread,
Aug 25, 2003, 5:16:36 AM8/25/03
to
Yes, I tried this and other combinations of that flags.
I also tried to change CoInitFlags.
Unfortunatelly no result :(


Użytkownik "Robert" <rob...@nospam.com> napisał w wiadomości
news:3f49...@newsgroups.borland.com...

Robert

unread,
Aug 26, 2003, 10:24:18 AM8/26/03
to
hi

i have tested this (the static page with the frameset...)
and i am getting the same "random" errors

i also think that there is a big problem when using websnap with an COM
interface to an activeX server
(with CoInitializeEx()... and so on)

hello borland-people: any idea how to connect to an ActiveX server when
using websnap ??? (i think this is the main problem ???)

robert


"Paulo" <p.ko...@gazeta.pl> schrieb im Newsbeitrag
news:3f45ebfa$1...@newsgroups.borland.com...

Steven Kamradt

unread,
Aug 26, 2003, 11:05:34 AM8/26/03
to
Robert wrote:

> hi
>
> i have tested this (the static page with the frameset...)
> and i am getting the same "random" errors
>
> i also think that there is a big problem when using websnap with an
> COM interface to an activeX server
> (with CoInitializeEx()... and so on)
>
> hello borland-people: any idea how to connect to an ActiveX server
> when using websnap ??? (i think this is the main problem ???)
>
> robert
>

Robert,

I am not using Apache, so my findings might not work the same. I am,
however, using IIS/ISAPI and also accessing multiple ActiveX servers
from various vendors and had to do the following to get it to work:

1) Add as the first unit in the library "COMINIT" which looks like the
following:

unit cominit;

interface

uses
ActiveX;

implementation

initialization
CoInitializeEx(nil,COINIT_MULTITHREADED);
finalization
CoUninitialize;
end.

2) On your TWebAppPageModule, add
CoInitializeEx(Nil,COINIT_MULTITHREADED) to the OnActivate event and
CoUninitialize to the OnDeactivate event.

This corrected the problems I was having with random access violations
when running under idDebugger/idRunner/IIS. Each "server" was behaving
differently before, but now they are all consistant.

Paulo

unread,
Aug 26, 2003, 11:32:52 AM8/26/03
to
Nope - that didn;t help. The error still occurs. Unfortunatelly....

Paulo

unread,
Aug 26, 2003, 11:38:54 AM8/26/03
to
The problem is not involvew with ActiveX as a technology. I tested my
situation with Delphi 6 and it worked ok ! I checked the difference, and
I found out, that they changed the way to *export* interfaces to the
script engine. In D6 there are interfaces specified, and the whole thing
works well, while in D7 all objects descend from TDispatchObject which
uses some *magic* way to export properties and methods of pure delphi
classes to ActiveX. I think that bug is somewhere in that routines, but
I was unable to lacalize it. I surrendered when I saw as they put the
call and parameters on the processor's stack and make assembler call.
I'm not that kind of GURU to debug this stuff :(

Pavel

unread,
Nov 6, 2003, 1:59:43 AM11/6/03
to
We have tried to solve this problem with CoInitializeEx, but on my 2 CPU PC
(win2k, D7) websnap with apache still generate "random" error. The problem
was removed with addition critical section in ApacheTwoApp unit and using
CoInitializeEx. Her is code.
unit ApacheTwoApp;

.

.

var CS:TRTLCriticalSection;

function DefaultHandler(r: Prequest_rec): Integer; cdecl;

var

RequestedHandler: string;

begin

EnterCriticalSection(CS);

try

RequestedHandler := r^.handler;

if SameText(RequestedHandler, Handler) then

Result := (Application as TApacheTwoApplication).ProcessRequest(r^)

else

Result := DECLINED;

finally

LeaveCriticalSection(CS);

end;

end;

procedure RegisterHooks(p: Papr_pool_t); cdecl;

begin

EnterCriticalSection(CS);

try

ap_hook_handler(DefaultHandler, nil, nil, APR_HOOK_MIDDLE);

if Assigned(OnRegisterHooks) then

OnRegisterHooks(p);

finally

LeaveCriticalSection(CS);

end;

end;

.

.

.

.

initialization

InitializeCriticalSection(CS);

InitApplication;

finalization

DeleteCriticalSection(CS);

end.

Pavel Zedník


"Steven Kamradt" <ste...@resource-dynamics.com> píše v diskusním poíspivku
news:3f4b773e$1...@newsgroups.borland.com...

Pavel

unread,
Nov 7, 2003, 3:53:35 AM11/7/03
to
I forgot to remark, that the problem may by resolved with seting
"ThreadsPerChild 1" in apache config. file httpd.cnf. But the performance is
lower.

Pavel

"Pavel" <pavel....@seznam.cz> píše v diskusním příspěvku
news:3fa9...@newsgroups.borland.com...

Paulo

unread,
Nov 10, 2003, 2:18:23 PM11/10/03
to
Yes, I know that Critical Section is a solution, but it lowers the
performance. What we managed to do is to lock only JScript parser (which
actually is a problem) not to allow it to parse two JScripts at a time.
There is not need to set the CS for the whole request (there is a lot of
non-parse time you waste this way: IO, DB operation for example).

Regards

Pawel Kowalik

Użytkownik Pavel napisał:

> We have tried to solve this problem with CoInitializeEx, but on my 2 CPU PC
> (win2k, D7) websnap with apache still generate "random" error. The problem
> was removed with addition critical section in ApacheTwoApp unit and using
> CoInitializeEx. Her is code.
> unit ApacheTwoApp;
>
> ..
>

> ..

> ..
>
> ..

0 new messages