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.

Vent Publications Never Die... They Duplicate.

See original GitHub issue

In integrating Vent into my app, I just noticed through debugging that my Vent publication is duplicating responses to subscriptions and continuing to fire messages after calling handler.stop(). When client browsers get refreshed or are HCR’d (Hot Code Reload), you end up getting lots of duplicated publish responses.

I have a publication:

Vent.publish({
  'manualReactivity': function(someId) {
    this.on('manualReactivity::' + someId + '::updated', function(response) {
      console.log("manualReactivity PUBLISHER running...");
      return response;
    });
  }
});

I have my Vent.subscribe call in my parent-most template so it can always be listening for updates. In my parentTemplate.onCreated I am subscribing:

var instance = this;

instance.manualReactivityListener = Vent.subscribe('manualReactivity', instance.someId);
instance.manualReactivityListener.listen(function(response) {
    // Do stuff...
});

In my parentTemplate.onDestroyed I am stopping the listener which I thought would tear everything down:

var instance = this;

instance.manualReactivityListener.stop();

If I open four browsers and watch the console on the server after triggering a Vent.emit('manualReactivity::someId::updated', {someObject}); in my code somewhere, I see the following expected output:

manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...

If I then refresh all four client browsers, and trigger the Vent.emit again, the output is duplicated with the old subscriptions and the new ones created by the refresh:

manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...
manualReactivity PUBLISHER running...

Same if I an HCR happens. After lots code updates and HCRs in development, I noticed the output above really growing.

At first I thought the problem was that my template.onDestroyed wasn’t getting called because of issues with the window closing/refreshing and it not having time to run the onDestroyed. I thought maybe it needed to go into a window.addEventListener('beforeunload')... Before doing that, I tried testing instance.manualReactivityListener.stop(); by moving it to somewhere I can trigger. After running the line, I do see that the subscription code on my client stops running as expected. But the the above output from the publication code keeps running and duplicating.

What’s the Vent policy on ending publications? Are they not killed when calling handler.stop()? Do they die after a certain amount of time? Could this be problematic for the server - with 1000+ clients?

If needed, I can submit a repo, but this is easy to duplicate.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
nathan-muircommented, Apr 17, 2018

@evolross Suppose you wrote something like:

Vent.publish({
    'followThreads'(thread1, thread2, thread3) {
        this.on(`threads::${thread1}::new_message`, ({message}) => {
            return {thread: thread1, message};
        });
        this.on(`threads::${thread2}::new_message`, ({message}) => {
            return {thread: thread2, message};
        });
        this.on(`threads::${thread3}::new_message`, ({message}) => {
            return {thread: thread3, message};
        });
    }    
})

Yes, you would probably use a loop, but we’re illustrating that this.on could be called multiple times in the one publish handler.

0reactions
evolrosscommented, Apr 17, 2018

Ah… understood. I see the use-case now. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Predictors of Time to Death After Terminal Withdrawal ... - NCBI
We examined the timing of death and predictors of time to death after terminal withdrawal of mechanical ventilation among patients who died in...
Read more >
Magnetic Vent Covers- 6 Pack (8" x 15") - Amazon.com
These vent covers are THICK and STRONG! They're flexible enough to get your dies off of but are sturdy enough to remain flat...
Read more >
Clothes Dryer Vents: The Proper and the Improper
The photo below illustrates how dirty many dryer ducts are and most people would have no idea until they either (1) have a...
Read more >
The Book Thief - SharpSchool
HERE IS A SMALL FACT. You are going to die. I am in all truthfulness attempting to be cheerful about this whole topic,...
Read more >
What Is Dead May Never Die | Game of Drones | A Dull “Game of ...
An improved sewing thimble having an elongated, tubular body consisting of a pliable material, such as rubber, wherein a plurality of vent holes...
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