-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Client doesn't report the server abruptly going away in the middle of event emission (only in NodeJS) #22
Comments
Hmm, seems like this bug is exclusive to NodeJS. I've tried replicating the same behaviour in the browser, but it fails immediately when the server gets killed. Here are my repro steps:
import { GraphQLSchema, GraphQLObjectType, GraphQLString } from 'graphql';
import http from 'http';
import { createHandler } from 'graphql-sse';
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
hello: {
type: GraphQLString,
resolve: () => 'world',
},
},
}),
subscription: new GraphQLObjectType({
name: 'Subscription',
fields: {
greetings: {
type: GraphQLString,
subscribe: async function* () {
for (const hi of ['Hi', 'Bonjour', 'Hola', 'Ciao', 'Zdravo']) {
yield { greetings: hi };
await new Promise((resolve) => setTimeout(resolve, 3000));
}
},
},
},
}),
});
const handler = createHandler({ schema });
const server = http.createServer(async (req, res) => {
if (!req.url.startsWith('/graphql/stream')) {
return res.writeHead(404).end();
}
try {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader('Access-Control-Allow-Methods', '*');
res.setHeader('Access-Control-Allow-Headers', '*');
if (req.method === 'OPTIONS') {
// preflight
return res.writeHead(204).end();
}
return await handler(req, res);
} catch (err) {
console.error(err);
if (!res.headersSent) {
res.writeHead(500);
}
return res.end();
}
});
server.listen(4000);
console.log('Listening to port 4000');
subscription {
greetings
}
I've Googled around but couldn't find any clues about why this test fails: graphql-sse/src/__tests__/client.ts Lines 176 to 194 in 72d284a
Could it be |
Sure I'll take a look @enisdenjo - will let you know what I find. |
I am closing this issue with 8f002f1 because the issue stems from v2 of |
This comment was marked as resolved.
This comment was marked as resolved.
@enisdenjo what a great find. Thank you so much for your persistence in identifying the resolution! |
Kudos, and big thanks, to @brentmjohnson for discovering this bug over at #21!
As per #22 (comment), this issue seems to be exclusive to NodeJS environments.
Expected Behaviour
If the server goes away abruptly during event emission, the client reports the error to the sink.
Actual Behaviour
If the server goes away abruptly during event emission, the client gets stuck and the sink is never finalised.
The text was updated successfully, but these errors were encountered: