Recent

Author Topic: (Indy) Web application get page error  (Read 11395 times)

asdf121

  • New Member
  • *
  • Posts: 35
Re: (Indy) Web application get page error
« Reply #15 on: November 10, 2018, 06:45:03 pm »
Did you define a TIdCompressorZLib for using gzip? I think there is an issue because my old code does not work anymore after updating Indy to latest version.
Maybe it's related to the change from Updating various DLL related functions to use THandle instead of HMODULE? If I remove the support for gzip from my TIdHTTP object, it works flawless.

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: (Indy) Web application get page error
« Reply #16 on: November 11, 2018, 01:10:11 am »
how? if like this not found

idhttp1.Compressor:=nil;
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: (Indy) Web application get page error
« Reply #17 on: November 11, 2018, 04:33:14 pm »
Ok, I've done other tests and I understand that the problem is not the GET call, the problem is that the http server crashes when idhttpserver1.OnCommandGet is called the second time but has not finished running the first one yet. I modified the source, if you open it you will see that now there is a sleep (4000); in order to give you time to load the page in the browser the second time. Can someone tell me what's wrong? I do not understand. It should be managed multithreaded so it should not happen. Ideas?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: (Indy) Web application get page error
« Reply #18 on: November 12, 2018, 11:20:12 am »
No suggestions? Has anyone at least managed to replicate my problem?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: (Indy) Web application get page error
« Reply #19 on: November 12, 2018, 01:34:22 pm »
In the face of other tests I understood that the problem exists only if the requests are made by the same PC on which the http server runs. If I do it with another computer, or the smartphone or tablet, the server does not crash. Ideas?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: (Indy) Web application get page error
« Reply #20 on: November 12, 2018, 08:22:08 pm »
You know a Lazarus developer from Indy team?!

I'm the only developer left on the team.  Other remaining members are admins.

I found the place where the problem is generated, in the IdHTTP unit there is the function

Code: Pascal  [Select][+][-]
  1. function TIdCustomHTTP.Get(AURL: string
  2.   {$IFDEF STRING_IS_ANSI}; ADestEncoding: IIdTextEncoding = nil{$ENDIF}
  3.   ): string;
  4. begin
  5.   Result := Get(AURL, []{$IFDEF STRING_IS_ANSI}, ADestEncoding{$ENDIF});
  6. end;  
  7.  

It happens that if the server receives two simultaneous calls it closes. This is on linux and on mac osx. Only I do not understand how to solve. Some idea?

What 2 calls are you referring to?  There is only 1 GET request in that code.  Just one overloaded Get() calling another overloaded Get() with extra parameters.  But only 1 GET request is sent to the server.

Ok, I've done other tests and I understand that the problem is not the GET call, the problem is that the http server crashes when idhttpserver1.OnCommandGet is called the second time but has not finished running the first one yet.

What kind of crash EXACTLY? What is your logging telling you?

TIdHTTPServer (like all of Indy's TCP servers) is a multi-threaded component.  The OnCommandGet event (and other events) is triggered in the context of a worker thread for a particular client (represented by the AContext parameter).  OnCommandGet can be called multiple times in parallel, but only when receiving requests from multiple clients.  For a given client, the events are serialized, and HTTP is a command/response protocol, so it is simply not possible for OnCommandGet to be called for a client while it is already running for that same client.  But, it can certainly be called for another client.  A browser can (and frequently does) make multiple TCP connections to a server.  That is perfectly normal.  It is your responsibility to make sure the code in your event handlers is thread-safe.

I modified the source, if you open it you will see that now there is a sleep (4000); in order to give you time to load the page in the browser the second time.

That merely blocks a client from responding for 4 seconds.  If you ask your browser to make a new request while the previous request is still blocked, the browser will simply open a new TCP connection to the server (thus running a new thread in the server) to make that new request.
« Last Edit: November 12, 2018, 08:38:31 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: (Indy) Web application get page error
« Reply #21 on: November 13, 2018, 08:13:35 am »
I meant two calls from the clients. If I open the browser from the same computer it is the server and very quickly launch two pages the program closes without daring errors. Can you explain why? On windows it does not happen, only on unix-like systems (I tried mac osx and ubuntu).
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: (Indy) Web application get page error
« Reply #22 on: November 13, 2018, 08:51:46 pm »
If I open the browser from the same computer it is the server and very quickly launch two pages the program closes without daring errors.

Then you are doing something wrong in your code.  You need to debug it to see how it reacts with multiple browser requests being made at the same time.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: (Indy) Web application get page error
« Reply #23 on: November 14, 2018, 08:11:40 am »
My code is the one I have above. It comes from one of the examples released with the package. I do not doubt it is a mistake. I'm asking for help precisely because I do not understand where I'm wrong.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: (Indy) Web application get page error
« Reply #24 on: November 14, 2018, 08:58:48 pm »
I do not doubt it is a mistake. I'm asking for help precisely because I do not understand where I'm wrong.

Well, you didn't answer my earlier questions yet:

Quote
What kind of crash EXACTLY? What is your logging telling you?

You are the one running the server.  How does it behave exactly?  HOW is it crashing?  WHAT is being reported to you when the crash is detected?
« Last Edit: November 19, 2018, 09:33:08 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: (Indy) Web application get page error
« Reply #25 on: November 15, 2018, 08:24:38 am »
As I have already told you, it does not report any errors, simply the program closes itself.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: (Indy) Web application get page error
« Reply #26 on: November 19, 2018, 09:34:17 pm »
As I have already told you, it does not report any errors, simply the program closes itself.

As I stated earlier, you need to step through your code with a debugger and find out exactly what is happening.  I can't help you with that.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018