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

Service crash after close browser tab with active subscription #74

Closed
nonlux opened this issue Apr 30, 2020 · 1 comment
Closed

Service crash after close browser tab with active subscription #74

nonlux opened this issue Apr 30, 2020 · 1 comment

Comments

@nonlux
Copy link

nonlux commented Apr 30, 2020

I have few services with qraphql subscription.
As example record service with graphql subscription:

  actions: {
    addNew: {
      graphql: {
        input: `input NewRecordInput {
          title: String!
         }
        `,
        mutation: `addNewRecord(input: NewRecordInput!): Record`
      },
      async handler(ctx) {
        const {user} = ctx.meta;
        const { title} = ctx.params.input;
        const record = {
          title,
          user: user._id,
          createdAt: Date.now(),
          type: 'inbox',
        };
        try {
        const result = await this.adapter.collection.insert(record);
          const newRecord = result.ops[0];
          await this.broker.broadcast('graphql.publish', {
            tag: 'RECORD.INBOX',
            payload: { data: {_id:newRecord._id.toString() }},
          });
          return newRecord;
        } catch(err) {
          console.log(err);
          throw err;
        }
      }
    },
     'new.inbox.event': {
      params: { payload: 'object' },
      graphql: {
        type: `type IdPart{
         _id: ID,
        }`,
        subscription: 'newInboxRecord: IdPart',
        tags: ['RECORD.INBOX'],
      },
      handler(ctx) {
        return ctx.params.payload.data;
      },
    },
  },

But sometimes after closing client on browser tab with active subscription core web-service with ApiGateway and ApolloService mixins crash with error:

node_modules/ws/lib/websocket.js:757
  websocket.readyState = WebSocket.CLOSING;
                       ^

TypeError: Cannot set property 'readyState' of undefined
    at Socket.socketOnClose (/node_modules/ws/lib/websocket.js:757:24)
    at Socket.emit (events.js:327:22)
    at Socket.EventEmitter.emit (domain.js:485:12)
    at TCP.<anonymous> (net.js:674:12)
@nonlux
Copy link
Author

nonlux commented Apr 30, 2020

#51
Sorry for dublicate

@nonlux nonlux closed this as completed Apr 30, 2020
arash16 added a commit to arash16/moleculer-apollo-server that referenced this issue Mar 8, 2021
This causes socket listeners to close gracefully.
Fixes issues moleculerjs#51 and moleculerjs#74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant