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

Websocket multiple subscription from same ip causes duplicate responses #356

Closed
kuoweilai opened this issue Feb 23, 2022 · 5 comments
Closed

Comments

@kuoweilai
Copy link

kuoweilai commented Feb 23, 2022

Describe the bug
When I run two instances and subscribe to the same websocket, although the subscription returns different subscription id, it causes cuplicate responses.

To Reproduce

var main_provider = "ws://localhost:8546";
const Web3 = require('web3');
const web3 = new Web3(main_provider);

const monitor = async () => {

	var subscription = web3.eth.subscribe('newBlockHeaders', async (error, block_info) =>{

		if (!error) {
			console.log('[Block Number] ' + block_info.number.toString());
		}
	});
};
monitor();

If you run the code from n terminals, each terminal will print the result n times. (in the screenshot, you can see the block 1609002 shows twice because i ran two instances. After i shut down another instance, it becomes normal again in block 1609005.)
Screen Shot 2022-02-22 at 8 43 56 PM

Expected behavior
I think they shouldn't affect each other

Desktop (please complete the following information):
Ubuntu 20.04
using v0.6.6 binary, but this issue was there from the first day of the mainnet

@kaber2
Copy link

kaber2 commented Feb 23, 2022

The cause of this seems to be some buggy handling of subscriptions in ethermint. Basically the subscription functions iterate over all filters, then for every filter of the same type, they deliver one event. The proper thing to do would be to either use only one filter for all subscriptions or just deliver the events from the filter created for each individual subscription.

The fix should be relatively simple, just remove the api.filter iteration in rpc/websocket.go and use the filter created before.

@kuoweilai
Copy link
Author

@kaber2 So I probably need to build myself to resolve this issue right? Thank you so much!

and hi @yihuang, should I submit an issue in ethermint? Thank you so much

@kuoweilai kuoweilai reopened this Feb 24, 2022
@yihuang
Copy link
Collaborator

yihuang commented Feb 24, 2022

@kaber2 So I probably need to build myself to resolve this issue right? Thank you so much!

and hi @yihuang, should I submit an issue in ethermint? Thank you so much

it's fine, we'll handle it from here, thanks for your reporting 🙏

@yihuang
Copy link
Collaborator

yihuang commented Feb 24, 2022

The cause of this seems to be some buggy handling of subscriptions in ethermint. Basically the subscription functions iterate over all filters, then for every filter of the same type, they deliver one event. The proper thing to do would be to either use only one filter for all subscriptions or just deliver the events from the filter created for each individual subscription.

The fix should be relatively simple, just remove the api.filter iteration in rpc/websocket.go and use the filter created before.

yeah, it's exactly the reason you mentioned, just submitted a fix: evmos/ethermint#955

@yihuang
Copy link
Collaborator

yihuang commented Mar 7, 2022

the fix is backported to https://github.com/crypto-org-chain/cronos/releases/tag/v0.6.7 for mainnet nodes.

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

3 participants