question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why are the connections duplicated?

See original GitHub issue

Rails 6.0.3.2 @rails/actioncable 6.0.3 @types/actioncable 5.2.3 actioncable-vue 2.3.0


I have some list. Each item in this list is wrapped in a component. Inside this component I have a subscription to the channel.

const CHANNEL_NAME = 'GoodNameChannel'

export default {
  props: {
    item: {
      type: Object,
      required: true
    }
  },

  channels: {
    [CHANNEL_NAME]: {
      connected() {
        console.info(
          `${CHANNEL_NAME}: connected()`, this.item.id
        )
      },
      received(data) {
        console.info(
          `${CHANNEL_NAME}: received()`, data
        )
      },
      disconnected() {
        console.info(
          `${CHANNEL_NAME}: disconnected()`
        )
      }
    }
  },

  mounted() {
    this.$cable.subscribe({
      channel: CHANNEL_NAME,
      item_id: this.item.id
    })
  }
}

There are two items in the list. So there are two components within which the subscription takes place.

If we look at the server logs, we will see these two subscriptions:

15:43:20 web.1       | GoodNameChannel is transmitting the subscription confirmation
15:43:20 web.1       | GoodNameChannel is streaming from good_name_item:Z2lkOi8vZ28tc2F5LWFjYWRlbXktc3xhdGZvcm0vTWVzc2VuZ2VyOjpSb29tLzQ0
15:43:20 web.1       | GoodNameChannel is transmitting the subscription confirmation
15:43:20 web.1       | GoodNameChannel is streaming from good_name_item:Z2lkOi8vZ28tc2F5LWFjYWRlbXktc3xhdGZvcm0vTWVzc2VuZ2VyOjpSb29tLzQz

But if look at the result of this code:

console.info(
  `${CHANNEL_NAME}: connected()`
)

Then you can see the following:

GoodNameChannel: connected() 123 GoodNameChannel: connected() 124 GoodNameChannel: connected() 123 GoodNameChannel: connected() 124

That is, this code is executed 4 times.

mounted() is executed twice as expected (once for each component)

Why is this happening?

In other places, where there are more than 2 items (components) in the list, I get not duplication, but item * n, where n is more than 2 or even 4.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
afunocommented, Aug 1, 2020

@mclintprojects I moved the subscription to the channel from each list item component to the root list component. This fixed the problem with “multiplying” subscriptions on the JS side. Thank you.

0reactions
mclintprojectscommented, Jul 27, 2020

@afuno Yes, kindly email me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Duplicate Active Directory replication connections are created
This issue is caused by either a lack of network connectivity or by another problem that disrupts replication on the Intersite Topology ......
Read more >
connections Set allows duplicates instances from same client
Yes this is normal, every new connection is unique. Your operating system may limit the number of open file descriptors imposing a limit...
Read more >
Duplicate Publicized connections - WordPress.org
If you're seeing “duplicates” on the Post editor page, this might mean that your user account is seeing connections it doesn't have access...
Read more >
Duplicate Connection - Digi International
The "Duplicate Connection" message displays if a Hub is found twice and appears twice in the AnywhereUSB Manager. This occurs if you have...
Read more >
duplicate command - Autodesk
Input connections to the node to be duplicated, are also duplicated. This would result in a fan-out scenario as the nodes at the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found