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

Always teardown subscriptions on completion #846

Merged
merged 2 commits into from
Aug 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 16 additions & 10 deletions lib/subscription-connection.js
Expand Up @@ -271,6 +271,7 @@ module.exports = class SubscriptionConnection {
}

this.sendMessage(this.protocolMessageTypes.GQL_COMPLETE, id, null)
this.handleGQLComplete(id)
}

async _executeQueryOrMutation ({ query, context, variables, operationName, id }) {
Expand All @@ -283,6 +284,19 @@ module.exports = class SubscriptionConnection {
this.sendMessage(this.protocolMessageTypes.GQL_DATA, id, response)
this.sendMessage(this.protocolMessageTypes.GQL_COMPLETE, id, null)
}

handleGQLComplete (id) {
const sc = this.subscriptionContexts.get(id)
if (sc) {
sc.close && sc.close()
this.subscriptionContexts.delete(id)
}
const subIter = this.subscriptionIters.get(id)
if (subIter) {
subIter.return && subIter.return()
this.subscriptionIters.delete(id)
}
}

async handleGQLStop (data) {
if (this.context.onSubscriptionEnd) {
Expand All @@ -293,16 +307,8 @@ module.exports = class SubscriptionConnection {
return this.handleConnectionClose()
}
}
const sc = this.subscriptionContexts.get(data.id)
if (sc) {
sc.close && sc.close()
this.subscriptionContexts.delete(data.id)
}
const subIter = this.subscriptionIters.get(data.id)
if (subIter) {
subIter.return && subIter.return()
this.subscriptionIters.delete(data.id)
}

this.handleGQLComplete(data.id)
}

handleConnectionClose () {
Expand Down