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

Problem with multiple event listeners, duplicated event triggers #2485

Closed
NedeljkoKuzmanovic opened this issue Mar 11, 2019 · 7 comments
Closed
Labels

Comments

@NedeljkoKuzmanovic
Copy link

In my app i have multiple listeners (watchers) on different events of same contract. Nothing complicated.

let songAddedEvent = instance.SongAdded({}, {
        fromBlock: 'latest',
        toBlock: 'latest'
    });

songAddedEvent.watch(function (error, result) {
    if (error) {
        console.error(error);
    }
    console.log(result);
}
-------------
/////////////////////////////////////////
-------------------------
let newVoteEvent = instance.NewVote({}, {
        fromBlock: 'latest',
        toBlock: 'latest'
    });
newVoteEvent.watch(function (error, result) {
    if (error) {
        console.error(error); 
    }
    console.log(result);
}

Problem is that same event is caught multiple times, and strange thing is that event is caught exactly number_of_listeners times.

So in this case i have two listener on two different events and triggered listener is triggered 2 times

Tried with 3 listeners, then is triggered 3 times.

(Not all of them are triggered, just one listener multiple times).

I read this article #398 but doesn't explain why there is correlation between number of listeners and multiplication of event triggers.

Forgot to mention, console.log is called from same .js file and same line in that file.

Does somebody have an idea why is this happening??

I looking for answer about 5 months now , also i asked
https://ethereum.stackexchange.com/questions/62799/problem-with-multiple-event-listeners-duplicated-event-triggers?noredirect=1#comment79711_62799.

I don't know if this is a bug or i'm doing something wrong.

@nivida nivida added the 0.x.x label Mar 11, 2019
@nivida
Copy link
Contributor

nivida commented Mar 11, 2019

Version 0.20.x got his last maintenance release with v0.20.7 this means we do no longer work on v0.20.x of this project. Please use the latest 1.0 version and give some feedback about.

@nivida nivida closed this as completed Mar 11, 2019
@nivida nivida mentioned this issue Mar 28, 2019
12 tasks
@uwieske
Copy link

uwieske commented Apr 28, 2021

I have reproduced the same issue described above (title/description) in version 1.3.4 and 1.3.5. This issue has not been resolved. I also checked other issues submitted after the issue above had been submitted but I it seemed that this issue had never been resolved in newer versions. I will submit a new issue describing my scenario with the same underlying problem.

@DTIV
Copy link

DTIV commented Mar 24, 2022

Getting this error with version "^1.7.1"

@simonpalmer
Copy link

Is there any movement on this issue or a workround suggested?

@DTIV
Copy link

DTIV commented Mar 29, 2022

https://ethereum.stackexchange.com/questions/15402/duplicate-events-firing-in-a-web3-listener

3rd response worked for me, by creating a Set.

@simonpalmer
Copy link

Thanks, yes, I have ended up doing the same and using the tranactionHash as a sort of idempotency token. But it it a kludge, isn't it? I can't really see a blockchain reason why I would get multiple events, and certainly no link to the number of discrete event handlers I have. That sounds like a bug to me. I also tried different ways of subscribing to events, but web3 seems to propagate many events. This issues was marked as closed, maybe we should re-open it.

@alex1s1
Copy link

alex1s1 commented May 7, 2022

I've tried the 3rd response as well, but even that is not working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants