Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FireFox: Error in input stream #99

Open
shadedyin opened this issue Jun 9, 2024 · 1 comment
Open

FireFox: Error in input stream #99

shadedyin opened this issue Jun 9, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@shadedyin
Copy link

shadedyin commented Jun 9, 2024

I've noticed that text/event-stream responses in FireFox 127.0b9 (64-bit) eventually end up with Error in input stream error. This doesn't happen in Safari or Google Chrome. I've tested this by directly sending a fetch request with JavaScript, using URQL and through GraphiQL.

This seems to have to do with the timing for keepalive comments (it appears to be 10-12 seconds). If I artificially send comments from a resolver at 5 second intervals, the connection stays open in FireFox. If I increase the keepalive comment interval to 7.5 seconds or above, I eventually end up with an Error in input stream.

It would be nice to have a keepalive interval option on HandlerOptions.

I forked the repo and added a keepalive option to the HandlerOptions interface and used it where the pinger is created. However, it doesn't look like a pinger is being created for the request so I'm not sure where the keepalive comments I'm getting are even sent from.

With a little guidance I may be able to fix this and submit a pull request.

I've attached some screenshots and example code.

Screenshots

Screenshot 2024-06-09 at 12 33 10 Screenshot 2024-06-09 at 12 35 32

Example Code

import http from "http";
import { createHandler } from "graphql-sse/lib/use/http";
import { makeExecutableSchema } from "@graphql-tools/schema";
import { Repeater } from "@repeaterjs/repeater";

(async () => {
  const schema = makeExecutableSchema({
    typeDefs: `
      type Query {
        hello: String
      }
      type Subscription {
        wait: Boolean
      }
    `,
    resolvers: {
      Query: {
        hello() {
          return "Hello.";
        },
      },
      Subscription: {
        wait: {
          subscribe() {
            return new Repeater((push) => {
              push({ wait: true });
            });
          },
        },
      },
    },
  });

  const handler = createHandler({ schema, context: (req) => ({ req }) });

  const server = http.createServer(async (req, res) => {
    try {
      await handler(req, res);
    } catch (err) {
      console.error(err);
      res.writeHead(500).end();
    }
  });

  server.listen(8000);
  console.log("Listening to port 8000");
})();

Modified Resolver

...
Subscription: {
  wait: {
    subscribe(root, args, { req }, info) {
      const res = req.context.res;
      return new Repeater((push, stop) => {
        const interval = setInterval(() => {
          res.write(":\n\n");
        }, 5_000);
        stop.then(() => {
          clearInterval(interval);
        });
        push({ wait: true });
      });
    },
  },
},
...
@enisdenjo
Copy link
Owner

Hey hey, thanks for reporting and sorry for the delay! I've been very busy ahead of the upcoming GraphQL Conf 2024. A PR with an adjusted keepalive default, or even configurable one, would be very welcome and much appreciated! No pressure though; if not, I'll be revisiting this issue after the conf.

@enisdenjo enisdenjo added the bug Something isn't working label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants