Recent

Author Topic: THTTPApplication blocked by telnet connection  (Read 1935 times)

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan
THTTPApplication blocked by telnet connection
« on: June 20, 2024, 03:56:58 pm »
Hi,
Created small test app with THTTPApplication (actually it's sqldbrestbridge app with 3 endpoints), threaded := true, ssl=true etc, and everything works as expected and scales pretty good.
Connecting to my server with telnet myserver.org 51235 shows telnet prompt:
Connected to myserver.org.
Escape character is '^]'.

And thats' fine, but while telnet is waiting for input, other clients cannot connect to the server ?!? it blocks server to accept new connections while telnet app is connected. I don't know how to use OnAllowConnect and discard such connection, or at least free socket for another connection, in that case telnet can wait ....

MarkMLl

  • Hero Member
  • *****
  • Posts: 8015
Re: THTTPApplication blocked by telnet connection
« Reply #1 on: June 20, 2024, 05:09:52 pm »
That's an interesting one... I wrote my own Telnet code a few months ago to allow me to expunge LNet and can't for the life of me remember what I did for multiple connections.

Slightly later: OK, I made no attempt to use SSL and I've fixed the backlog parameter to fpListen() to be 1. My intention was very much to make the facility available as a debugging interface, or potentially to control a planetarium projector etc. so that was just about acceptable.

I think the big question is whether the library/component authors anticipated (or even knew about) the possibility that a user might connect via Telnet, or if they assumed that every connection would be a rapid open-request-close.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1428
    • Lebeau Software
Re: THTTPApplication blocked by telnet connection
« Reply #2 on: June 20, 2024, 05:31:10 pm »
And thats' fine, but while telnet is waiting for input, other clients cannot connect to the server ?!? it blocks server to accept new connections while telnet app is connected.

It would be very odd for an HTTP server to allow only 1 client connection at a time.  Do you have the same problem using an actual HTTP client with HTTP keep-alives enabled?  Can only 1 request be serviced at a time?
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: THTTPApplication blocked by telnet connection
« Reply #3 on: June 20, 2024, 08:21:11 pm »
Just sent thousands of requests (32 virtual users) over postman and it works. Just one telnet connection and server waits until that telnet connection interrupted by client app, when telnet session is killed, postman requests work again.
EDIT: fpc-3.3.1 trunk.
« Last Edit: June 20, 2024, 08:22:44 pm by zeljko »

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: THTTPApplication blocked by telnet connection
« Reply #4 on: June 20, 2024, 08:24:04 pm »
And thats' fine, but while telnet is waiting for input, other clients cannot connect to the server ?!? it blocks server to accept new connections while telnet app is connected.

It would be very odd for an HTTP server to allow only 1 client connection at a time.  Do you have the same problem using an actual HTTP client with HTTP keep-alives enabled?  Can only 1 request be serviced at a time?

Problem is that connection isn't passed to any of http* components at all. I can see it only in TInetServer.OnAcceptConnect, it does not hit InitRequest, HandleRequest or anything http* related.

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: THTTPApplication blocked by telnet connection
« Reply #5 on: June 21, 2024, 01:44:49 pm »
Found that problem is in ssl_accept() which blocks forever on eg telnet connection, no idea how to fix this (opensslsockets.pp function TOpenSSLSocketHandler.Accept: Boolean). Maybe using select() ? Any ideas ?

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: THTTPApplication blocked by telnet connection
« Reply #6 on: June 21, 2024, 04:16:10 pm »
Ok, solved by using fpAlarm() inside TOpenSSLSocketHandler.Accept...don't know if it's best solution but it works :)

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1428
    • Lebeau Software
Re: THTTPApplication blocked by telnet connection
« Reply #7 on: June 21, 2024, 11:36:23 pm »
Found that problem is in ssl_accept() which blocks forever on eg telnet connection

Makes sense, but even so, I would still expect the HTTP server to be able to accept other clients while the Telnet client is blocked.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

zeljko

  • Hero Member
  • *****
  • Posts: 1668
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: THTTPApplication blocked by telnet connection
« Reply #8 on: June 22, 2024, 12:39:29 pm »
Gnutls have ability to timeout handshake for such connections, but openssl  does not, so as I can see by googling alarm is one of the solutions (unix only, don't know if there's anything like fpAlarm on windows)

 

TinyPortal © 2005-2018