Subscriptions-transport-ws: Heroku error - Idle connection

Created on 23 Jul 2018  路  10Comments  路  Source: apollographql/subscriptions-transport-ws


I am having an issue running with running subscriptions on Heroku. The inital connection works but subseqent calls get a H15 error: https://devcenter.heroku.com/articles/error-codes#h15-idle-connection

Since Heroku's timeout is 55s, I have set the keepAlive as low as 10000ms and still I get the error. I have tried having the server send pings, but then mutation broadcast doesn't work.

Here is the code for my server: https://github.com/idahogurl/stock-watch/blob/ws-fix/server/server.babel.js

Here is the code for my client: https://github.com/idahogurl/stock-watch/blob/ws-fix/app/index.jsx

I should mention that my code works perfectly on my local environment.

has-reproduction

Most helpful comment

I have been having the same issue for weeks. I just resolved it by setting the keepAlive option (which I didn't set before) to 10000ms.

I used this configuration and checked in Chrome Dev tools if the client was now receiving a keepAlive message.

new SubscriptionServer({
    execute,
    subscribe,
    schema: executableSchema,
    keepAlive: 10000,
  }, {
    server,
    path: '/subscriptions',
  })
new SubscriptionClient(GRAPHQL_ENDPOINT, {
  reconnect: true,
  reconnectionAttempts: 50,
  lazy: true,
  timeout: 20000,
})

Then after I deployed to heroku, all H15 errors disappeared. (I had 1 error every 55 seconds for each connected user and my logs looked like a Christmas tree 馃槺).

This post helped me getting on the right track Prevent H12 and H15 errors when deploying Socket.IO on Heroku:

H15 errors are caused by WebSocket connections which have no activity for 55 seconds.

@idahogurl Hope it helps even if this is basically what you tried 馃様

All 10 comments

i noticed ur question while i was struggling with getting mine working on heroku,
iam sure u wld hv solved it by now ::D

it might be just an issue with how u r setup,
i got it working here https://mnd-pyratin.herokuapp.com/Messages/Edges,

my git repo: https://github.com/pyratin/mnd

I have been having the same issue for weeks. I just resolved it by setting the keepAlive option (which I didn't set before) to 10000ms.

I used this configuration and checked in Chrome Dev tools if the client was now receiving a keepAlive message.

new SubscriptionServer({
    execute,
    subscribe,
    schema: executableSchema,
    keepAlive: 10000,
  }, {
    server,
    path: '/subscriptions',
  })
new SubscriptionClient(GRAPHQL_ENDPOINT, {
  reconnect: true,
  reconnectionAttempts: 50,
  lazy: true,
  timeout: 20000,
})

Then after I deployed to heroku, all H15 errors disappeared. (I had 1 error every 55 seconds for each connected user and my logs looked like a Christmas tree 馃槺).

This post helped me getting on the right track Prevent H12 and H15 errors when deploying Socket.IO on Heroku:

H15 errors are caused by WebSocket connections which have no activity for 55 seconds.

@idahogurl Hope it helps even if this is basically what you tried 馃様

Hi @pyratin
Thanks for the response. I will have to try your code. Sorry @paulnta I did try the keepAlive setting :) What does both your package.json look like?

@all, do you see any server performance problem using the keepAlive: ANY_NUMBER_IN_MS?

Default is disabled, why? What happens when disabled? And why Heroku still needs a keepAlive?

I'm having the exact same error, but setting keepAlive does not seem to help. I am using ApolloServer like so:

new ApolloServer({
    typeDefs,
    resolvers,
    context: async (context) => {
       ...
    },
    subscriptions: {
      keepAlive: 10000,   <-- Added keepAlive
      onConnect: ...
    },
  });

Any ideas on how to fix?

I have been having the same issue for weeks. I just resolved it by setting the keepAlive option (which I didn't set before) to 10000ms.

I used this configuration and checked in Chrome Dev tools if the client was now receiving a keepAlive message.

new SubscriptionServer({
    execute,
    subscribe,
    schema: executableSchema,
    keepAlive: 10000,
  }, {
    server,
    path: '/subscriptions',
  })
new SubscriptionClient(GRAPHQL_ENDPOINT, {
  reconnect: true,
  reconnectionAttempts: 50,
  lazy: true,
  timeout: 20000,
})

Then after I deployed to heroku, all H15 errors disappeared. (I had 1 error every 55 seconds for each connected user and my logs looked like a Christmas tree 馃槺).

This post helped me getting on the right track Prevent H12 and H15 errors when deploying Socket.IO on Heroku:

H15 errors are caused by WebSocket connections which have no activity for 55 seconds.

@idahogurl Hope it helps even if this is basically what you tried 馃様

Link is currently broken. @paulnta do you remember what was all about?

We are still having the same issue. Did anyone get this to work while using ApolloServer or does everyone use just the middleware?

I'm also having the sam issue. Did you get it to work @iensu

@cmartin81 Nope, still just ignoring the issue and we haven't had enough time to refactor the code to use the middleware. :(

I am having the same issue. Is there a way to have the client ping the server?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KaiWedekind picture KaiWedekind  路  4Comments

anilanar picture anilanar  路  5Comments

booboothefool picture booboothefool  路  4Comments

prokher picture prokher  路  5Comments

malditogeek picture malditogeek  路  5Comments