El 8/1/21 a les 11:14, Luca Olivetti via fpc-pascal ha escrit:
El 8/1/21 a les 11:06, Michael Van Canneyt via fpc-pascal ha escrit:


Are you using https ?

No, plain text http.
An even weirder fact is that I seem to get the wrong ip address (i.e. the address of a different client).

I think I found the possible cause:

I have an own thread that spawns a TEmbeddedHttpServer (actually a derived class to manage server-sent-events, https://lists.lazarus-ide.org/pipermail/lazarus/2020-June/238072.html) with threaded:=true.

My thread has a method to manage the requests and it does this

    FRequest:=ARequest;
    Synchronize(@SyncNewConnection);
    if FCommandQueue<>nil then .....


I think that, since the method is called from a different thread for each request, if two requests come at the same time, the FRequest and/or the FCommandQueue (which is set in the synchronized method) could get mixed up.

I now did 2 things:

1) protected that part of the code with a critical section
2) use TThread.Synchronize(nil,..) (since it's not my thread but another one


   FCrit.Acquire;
   FRequest:=ARequest;
   TThread.Synchronize(nil,@SyncNewConnection);
   LocCommandQueue:=FCommandQueue;
   FCrit.Release;
   if LocCommandQueue<>nil then...



WDYT?

Am I right thinking that, even if several copies of the above method are running, each will get it's own local variables, so the LocCommandQueue variable (as well as the other locals) won't be clobbered by another copy?
Or should I declare them as threadvar?


Bye
--
Luca
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to