Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ERROR: AV's and IWButton.picture.data: the parameter is incorrect
#11
(02-08-2020, 06:17 AM)SorenJensen Wrote: The problem started when we were 3-4 users at the same time. Whether trying the same or different forms, we all experiences the problems with AV and picture.data error described above.

Notice: I'm not (deliberately, or as far as I know) using threads.
Just as a little background, IW uses multiple threads.  There is a new thread with each response from a client/browser.  A click or other action from the browser launches a thread on the server.  That thread processes the event until it finishes (ex: returns a response to the browser).

So, if two users simultaneously call the same code that is not thread safe then you'll have multiple threads using thread unsafe code.

Dan
Reply
#12
Hi Dan,

That sounds plausible. I haven't done anything special to handle threading, in fact I have not even considered it. And to be honest, I'm a little unsure of how to go about making my code thread safe.

Could you (or other of course) point to any examples or post a simple code, showing the principles ?

Regards
Soren
Reply
#13
(02-09-2020, 07:03 AM)DanBarclay Wrote:
(02-08-2020, 06:17 AM)SorenJensen Wrote: The problem started when we were 3-4 users at the same time. Whether trying the same or different forms, we all experiences the problems with AV and picture.data error described above.

Notice: I'm not (deliberately, or as far as I know) using threads.
Just as a little background, IW uses multiple threads.  There is a new thread with each response from a client/browser.  A click or other action from the browser launches a thread on the server.  That thread processes the event until it finishes (ex: returns a response to the browser).

So, if two users simultaneously call the same code that is not thread safe then you'll have multiple threads using thread unsafe code.

Dan
That needs more explanation.

I have some variables declared as session variables but almost all of them are declared in the implementation part of the unit. For example I create bmp: TBitmap in form onCreate and remove it in form onDestroy. I expect the bmp variable to be different for each user. All forms, while creating them, should, as I expect, belong to the user's session. So the bmp should be independent for each user connected at the same time to a different session. But now I see the same variable is shared between users, which should not happen. When I use
TIWForm1.Create(WebApplication).Show
in fact user2 gets the same implementation part variables as user1 has got. User1 sees variables of user2 and vice versa!!

But moving a number of variables from many forms to usersession unit does not make sense, does it? This way intraweb is of no use to me.
Reply
#14
Hi MrSpock,

Are you saying that only vars defined in the UserSession unit, is safe between the users and that all vars defined locally in forms being created from the main form, are NOT safe between the users ?

I have a number of forms being created the way you describe (form.create(webapplication).show) and though they do not have many "own" vars, there are a few in total. However, almost every form in turn creates a datamodule, on which I have a number of ADOQuery components, locally defined for the datamodule in question and where the code to access them is in the implementation part.

With what I'm experiencing with data from selects being mixed among users, I should maybe move all ADO components to the userSession, and only have the code to access them in the datamodules ?

But to be honest i am quite surprised about this. My expectations with intraWeb, in my case SA HTTP.SYS applications running as a service on a Win server, was that when setting ServerController.Cominitialization to MultiThreaded, ALL of the vars and forms being used and created during the session lifetime, was shielded from any other users calling the same service and having sessions created at the same time. If that is not the case, I should maybe forget about http.sys and focus on creating isapi applications and use them on the webserver instead.

Regards
Soren
Reply
#15
Soren

It is even worse. I have just made a test. I have moved all variables in question, marked below with arrows, to userSession unit.

uses
    GR32, Vcl.Graphics; //gr32 is for TBitmap32
Code:
TIWUserSession = class(TIWUserSessionBase)
    procedure IWUserSessionBaseCreate(Sender: TObject);
    procedure IWUserSessionBaseDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    s32,d32: Tbitmap32; <=
    m,d, bufor: Tbitmap; <=
    pic: Tpicture; <=

    wejścia: integer;
    pokażLicznik: boolean;
    procedure liczWejścia(rodzajDanych: jakieDane);
    procedure zapisujAdres;
    function DoS: boolean;
  end;
in session.oncreate I put

s32:= nil; d32:= nil; m:= nil; d:= nil; bufor:= nil; pic:= nil;
  d32:= Tbitmap32.Create; s32:= TBitmap32.Create;
  m:= TBitmap.Create; d:= TBitmap.Create; bufor:= Tbitmap.Create;
  pic:= Tpicture.Create;

and session.ondestroy

  if assigned(s32) then FreeAndNil(s32);
  if assigned(d32) then FreeAndNil(d32);
  if assigned(pic) then FreeAndNil(pic);
  if assigned(bufor) then FreeAndNil(bufor);
  if assigned(m) then FreeAndNil(m);
  if assigned(d) then FreeAndNil(d);

I opened two sessions in two different-browser tabs and I got the same variable values for user1 and user2!! My photography app does not work for more than one user at the same time. Perhaps the problem is related to TIWImage put on the form at design time, and this component uses shared value for both the users. When I draw on TIWImage.picture.bitmap.canvas, the same value is shown for the other user.

This is a serious security threat for any intraweb app and should be properly looked into.
Reply
#16
Sorry, a bit confused.. Is it still wrong even AFTER you moved everything to UserSession unit ?

I've read through the two below links, and as I read them, creating a datamodule, adding it to the uses clause of the UserSession unit, and creating (and destroying) it in UserSession code, should be the way to work with user safe vars. For me these are ADO components. By creating the Datamodule, putting all ADOAuery components on to that, and the ADO DBConnection as well, I should be able to used them in subcreated forms, with the prefix like: UserSession.dm.AdoQuery1.

According to the Session Overview document data should be safe for the user and shielded from other users and sessions. I expect that should be the same for your TBitmaps.

Link to Session / Webapplication description: https://doc.atozed.com/en/iw14/develop/session
and link to User Session Overview: https://doc.atozed.com/en/iw14/develop/s...-overview/
Reply
#17
(02-09-2020, 03:08 PM)SorenJensen Wrote: Sorry, a bit confused.. Is it still wrong even AFTER you moved everything to UserSession unit ?
You are correct.

I only could not move TIWImage to UserSession, as I had put it on the form at design time, and this may be the issue. I create forms using

procedure TIWForm2.napisLinkClick(Sender: TObject);
begin
  Release;
  TIWForm6.Create(WebApplication).Show;
end;

It seems that in this moment some form variables, I mean components, values are common for all users connected.

Again manual lacks proper description on how to cope with such basic problems. I feel like abandoning using intraweb.
Reply
#18
(02-09-2020, 03:02 PM)MrSpock Wrote: ...
I opened two sessions in two different-browser tabs and I got the same variable values for user1 and user2!! My photography app does not work for more than one user at the same time. Perhaps the problem is related to TIWImage put on the form at design time, and this component uses shared value for both the users. When I draw on TIWImage.picture.bitmap.canvas, the same value is shown for the other user.

MrSpock, 

Let me, please, understand better your test: have you opened two different web browsers (e.g., Chrome and Firefox), doing the test in both simultaneously, in which you realized that the variables had the same value, or did you open two tabs on the same web browser (e.g. Chrome or Firefox)?

Regards,
Joao Lira.
Reply
#19
MrSpock,

In the first of the two documents I linked to above, there are 2 notes:

1. To store session related variables, create members of the TUserSession class.
2. Do not work with variables declared in the var section, as these are global to all threads and won’t reflect session data properly.

As I read the two notes, the second of course is the culpit: never ever rely on vars not in usersession. However, the fist note holds a bit of a solution, and in combination with the description of User Session Overview (the second of the two links above) show how to add a an existing datamodule to the UserSession and how to create and destroy it in code in the usersession unit. For me I it means I should be able to create one datamodule, with one ADO DBConnection, and a number of ADOQoery or ADOStoredProc components, all being opened and linked together as part of the datamodule creation.

That way I should be able to open and execute SQL commands from my (later) created forms by using the prefix: UserSession.DM.ADOQuery1.

And for you, you should be able to create an empty imagefile, or a number of empty imageplaceholdes in the datamodule, and then use them in code at runtime. I'm not sure exactly what you do so this is just examples and a bit of guesswork, but I'm sure you get the idea.

I hope it will work like this and that my selects and table updates will be safe, once I have changed my application, just like I hope it will solve your problem. And I also hope those who know more about this, especially the AtoZed guys, will confirm this to be a possible solution.

Regards
Soren
Reply
#20
(02-09-2020, 03:34 PM)Joao Lira Wrote:
(02-09-2020, 03:02 PM)MrSpock Wrote: ...
I opened two sessions in two different-browser tabs and I got the same variable values for user1 and user2!! My photography app does not work for more than one user at the same time. Perhaps the problem is related to TIWImage put on the form at design time, and this component uses shared value for both the users. When I draw on TIWImage.picture.bitmap.canvas, the same value is shown for the other user.

MrSpock, 

Let me, please, understand better your test: have you opened two different web browsers (e.g., Chrome and Firefox), doing the test in both simultaneously, in which you realized that the variables had the same value, or did you open two tabs on the same web browser (e.g. Chrome or Firefox)?

Regards,
Joao Lira.
In two different web browsers.

There seems to have been a variable allowing having two separated sessions per IP, but from version to version it all changes and then does not work.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)