From e2fca3d588c5bc5dc28614b31c487ca63e4ca729 Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Thu, 28 Jan 2021 12:07:01 +1030 Subject: [PATCH] fix: subscription to servers disconnecting instantly --- app/mothership/subscribe-to-servers.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/mothership/subscribe-to-servers.ts b/app/mothership/subscribe-to-servers.ts index 9f78b152c..cd3317410 100644 --- a/app/mothership/subscribe-to-servers.ts +++ b/app/mothership/subscribe-to-servers.ts @@ -1,13 +1,14 @@ import { pubsub } from '../core'; import { SubscriptionClient } from 'graphql-subscriptions-client'; -import { MOTHERSHIP_GRAPHQL_LINK } from '../consts'; +import { MOTHERSHIP_GRAPHQL_LINK, ONE_SECOND } from '../consts'; import { userCache, CachedServers } from '../cache'; import { log as logger } from '../core'; const log = logger.createChild({ prefix: 'subscribe-to-servers'}); const client = new SubscriptionClient(MOTHERSHIP_GRAPHQL_LINK, { reconnect: true, - lazy: true, // only connect when there is a query + lazy: true, + minTimeout: ONE_SECOND * 30, connectionCallback: (errors) => { try { if (errors) { @@ -21,12 +22,8 @@ const client = new SubscriptionClient(MOTHERSHIP_GRAPHQL_LINK, { } }); -client.on('error', (error) => { - log.debug('url="%s" message="%s"', MOTHERSHIP_GRAPHQL_LINK, error.message); - client.close(); -}, null); - export const subscribeToServers = async (apiKey: string) => { + log.silly('Subscribing to servers with %s', apiKey); const query = client.request({ query: `subscription servers ($apiKey: String!) { servers @auth(apiKey: $apiKey) @@ -39,6 +36,10 @@ export const subscribeToServers = async (apiKey: string) => { // Subscribe const subscription = query.subscribe({ next: ({ data, errors }) => { + log.silly('Got data back with %s errors', errors?.length ?? 0); + log.silly('Got data %s', data); + log.silly('Got errors %s', errors); + if (errors) { // Log all errors errors.forEach((error: any) => {