Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Optional global timeout for http/jsonp calls on server #622

Closed
2 of 10 tasks
diestrin opened this issue Nov 14, 2016 · 5 comments
Closed
2 of 10 tasks

Optional global timeout for http/jsonp calls on server #622

diestrin opened this issue Nov 14, 2016 · 5 comments

Comments

@diestrin
Copy link

diestrin commented Nov 14, 2016

  • I'm submitting a ...
  • bug report
  • feature request
  • support request => Please do not submit support request here, see note at the top of this template.
  • What modules are related to this Issue?
  • express-engine
  • grunt-prerender
  • gulp-prerender
  • hapi-engine
  • universal-next
  • universal
  • webpack-prerender
  • Do you want to request a feature or report a bug?
    feature

  • What is the current behavior?
    If an http/jsonp endpoint, for some reason takes too much to respond, it will completely block the server respond.

  • What is the expected behavior?
    There should be a global timeout configuration for server http/jsonp requests.

  • What is the motivation / use case for changing the behavior?
    Delegating long responses to the client. Reduce the number of active clients waiting for a long response in server.

  • Please tell us about your environment:

  • Angular version: 2.1.0
  • Browser: all
  • Language: TypeScript 2.0
  • OS: Mac OS X
  • Platform: NodeJs
  • Other information
    I found this code, I think a simple timeout option can be passed there. Node already support passing the timeout value for http.request
@PatrickJS
Copy link
Member

PatrickJS commented Nov 15, 2016

this is a feature for http but you can also implement it yourself using rxjs. in rxjs you can use .timeout and even use .retryWhen for this feature. Right now there's a bug in rxjs where it's not canceling the setTimeout used in .timeout. so the server is waiting for all the setTimeouts to resolve. You can also create a .race right now that will work

Observable.race(
  this.http.get(url),
  Observable.of(null).delay(2000)
)

something like that above will work but if the http call fails it will wait until the delay is done so perhaps write a better version than that.

We can put this feature in the universal-starter as an example for the ApiService

@diestrin
Copy link
Author

I know I can do this with RxJS, in fact, I'm actually writing a workaround to fix this (overriding NodeBackend and NodeJsonpBackend to add the timeout).

The feature request is because when you have a code base with 30+ services and 50+ components, you can't go and add a .timeout() to all of the calls, and even if you have all the calls centralized in a couple of services, you don't really want this to run on client, just in server.

@diestrin
Copy link
Author

I just wrote this module as a workaround for this issue, in case anyone else finds it useful https://gist.github.com/diestrin/d9320064bf016cfd25210bb0452bb42a

@PatrickJS
Copy link
Member

also you can track this issue for .timeout
ReactiveX/rxjs#2134

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants