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

Problems with stream.close() #374

Closed
PierBover opened this issue Dec 17, 2020 · 2 comments
Closed

Problems with stream.close() #374

PierBover opened this issue Dec 17, 2020 · 2 comments

Comments

@PierBover
Copy link

PierBover commented Dec 17, 2020

I've found a couple of problems when using streams, all related to stream.close() on the browser.

The first one is that after using stream.close() it's not possible to restart the stream again with stream.start(). A new stream has to be created and started, otherwise this error is thrown:

The stream has already been started.

If this by design the error should at least inform that a new instance has to be created on every subscription.

The second problem is that after using stream.close() the internal event listeners are not being cleared up properly.

I tried to subscribe to an inexistent document (on purpose to trigger errors) with the following error handler:

stream.on('error', (data, event) => {
	stream.close();
	setTimeout(() => {
		initStream();
	}, 250);
});

After the error is triggered, the current stream is closed and a new one is created on each retry. Since the document does not exist, a new stream is created every 250ms in a loop. As you can see from Chrome's dev tools, the event listeners keep growing continually even though the garbage collector has been clearing the heap regularly:

image

It could be I'm missing something, but from looking at the source, there doesn't seem to be a method to destroy the stream properly.

It's possible the issue is actually in the polyfills of the Node libraries the JS driver requires to work on the browser. OTOH it's quite strange that the end user has to provide polyfills to use the JS driver on a modern browser...

@artem-kurnikov
Copy link
Contributor

@PierBover Hi! I was investigating the issue and found that the problem is in Chrome DevTools itself, here's the link to the issue created in fetch repo: JakeChampion/fetch#901.
Here Google Chrome issue links:
https://stackoverflow.com/questions/46695853/javascript-listeners-keep-increasing
https://bugs.chromium.org/p/chromium/issues/detail?id=576302

@PierBover
Copy link
Author

Thanks for checking it out @tigger9flow !

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

2 participants