Domraider / rxnet

PHP reactive network library, get the presentation slides
http://domraider.github.io/rxnet
MIT License
130 stars 15 forks source link

Timeout handling in Rxnet\Http client to avoid file descriptor leak #19

Closed madmatah closed 7 years ago

madmatah commented 7 years ago

With the current Http client, there are 2 (and maybe more) cases causing a file descriptor leak.

Consider the following code :

$http = new \Rxnet\Http\Http();
$http->get("http://localhost:8282/")
    ->subscribe(new StdoutObserver(), $scheduler)

We need to control connect timeout and response timeout.

Currently, the only way to handle this is by using the timeout() operator on the Observable returned by the get() method, like this :

$http = new \Rxnet\Http\Http();
$http->get("http://localhost:8282/")
    ->timeout(1000)
    ->subscribe(new StdoutObserver(), $scheduler)

But when the timeout is triggered, there is no way to close the file descriptor opened by the http client. If a process make a lot of http requests, it leads to a FD leak very fast.

I see 2 solutions here :

  1. Add options to control the connect timeout and response timeout in the $opts argument of the request() method, and handle the timeout inside the http client.
  2. Return something that implements DisposableInterface, to control the timeout from outside.

Any thoughts on the solution to implement ? You're welcome :)