Skip to content

Fetch hangs when trying to access HTTP streaming API #12912

Closed

Description

@mythz

Description

Cannot use W3C's Fetch streaming API to access a long-running SSE event-stream which just hangs until the stream has ended.

Reproduction

var start = Date.now();
console.log("fetch() ...", Date.now() - start, "ms");
fetch("http://chat.servicestack.net/event-stream")
  .then(res => {
      console.log("then() ...", Date.now() - start, "ms");
      if (!res.ok)
        throw new Error(`${res.status} = ${res.statusText}`);

      var reader = res.body.getReader();
      return reader.read().then(function handleNext(result) {
          console.log("read() ...", Date.now() - start);
      });
  })
  .catch(error => {
      console.log("catch() ", error.message, Date.now() - start, "ms");
  });

In React Native this prints out:

fetch() ... 0 ms
then() ... 32205 ms
catch()  undefined is not an object (evaluating 'res.body.getReader') 32212 ms

i.e. where it doesn't complete until the server terminates the connection and when it does complete it saysres.body isn't an object. Whereas in Chrome it works as expected:

fetch() ... 0 ms
then() ... 28 ms
read() ... 28

Solution

It doesn't look like fetch has implemented streaming support which means we can't access long-running HTTP Streams in React Native.

Additional Information

  • React Native version: latest 0.42.0
  • Platform: iOS
  • Operating System: OSX Sierra

Activity

  1. hramos commented on May 25, 2017

    @hramos
    Contributor

    We're cutting down on the number of outstanding issues, in order to allow us to focus. I'm closing this issue because it has been open for over 60 days with no activity. If you think it should still be opened let us know why. PRs are always welcome.

  2. mythz commented on May 25, 2017

    @mythz
    Author

    No kidding, so the new approach to resolving issues and reducing the issue count is to close down issues with small, stand-alone repros? Must be some new kind of approach to software quality control I missed the memo on. The reason why it should remain open is listed above in the issue, i.e. React Native can't access long-running HTTP Requests like SSE, except when debugging in Chrome where fetch (i.e. the primary method of communication) behaves as expected.

    If reporting issues isn't considered valuable then I guess this is the last issue React Native I'm reporting, Congratz on your impending Issue Zero milestone, I'm sure you'll get there in no time!

  3. hramos commented on May 26, 2017

    @hramos
    Contributor

    A bug report with no comments on it for sixty days must not be blocking that many people. We're trying to cut down on the number of issues so we can better focus on what's currently affecting users.

    I'm not saying that the bug is not worth fixing, but rather at this point if you're still blocked by this, it may well be worth looking into submitting a PR with a fix.

    I'd be happy to leave this issue linger in the open state for another sixty days, though I am not sure that will solve your problem.

  4. mythz commented on May 26, 2017

    @mythz
    Author

    It's not blocking me because I can periodically poll and auto-reconnect but the end-user UX is noticeably worse because RN fetch can't handle long-running HTTP requests, I suspect other users would find their own way to workaround the issue given they still need to develop their Apps with whatever tools/API they have available but to dismiss this noncompliance and use-case as not an issue worth knowing about is IMHO a poor approach for maintaining a high-quality project.

    Feel free to run your project as you like but I'd suggest using a label like up-for-grabs, low-priority or some other label that indicates the RN team wont be looking at it in the foreseeable future instead of just closing issues indiscriminately.

    I'd be happy to leave this issue linger in the open state for another sixty days,

    You're not doing me any favors by leaving the issue open, I thought I was doing you a favor by reporting an issue and submitting a small, stand-alone, verifiable example - but clearly the RN team doesn't view it as such so I'll be saving us both time and refraining from submitting any issues in future.

    though I am not sure that will solve your problem.

    This issue isn't my problem, it's React Native's problem with its W3C fetch implementation not functioning as expected. The other problem I see is how the RN team perceives the value of issues.

  5. luciozambon commented on Oct 18, 2017

    @luciozambon

    Will react-native ever supports SSE/EventSource?
    Is there any plan to support SSE or not to include it?
    IMHO the support of SSE would be really appreciated

  6. abogani commented on Oct 19, 2017

    @abogani

    @mythz How have you worked around this limitation (I meant missing SSE support in react-native)? Thanks!

  7. mythz commented on Oct 19, 2017

    @mythz
    Author

    @abogani no SSE behaviour in RN is fairly broken, ended up using really short heartbeat timeouts and put up with const reconnects.

  8. locked as resolved and limited conversation to collaborators on May 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions