MetaMask / metamask-extension

:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites
https://metamask.io
Other
12.06k stars 4.93k forks source link

Identify the root cause of the "Premature close" error #26337

Open danjm opened 3 months ago

danjm commented 3 months ago

We have long seen many errors in Sentry that have the message "Premature close". This PR addresses those that occur when the UI is closed, and when a connected dapp is closed.

This error is thrown from within the readable-stream module when multiple streams are passed to the same pipeline. We do not fully understand the issue yet, but it is suspected that we are incorrectly triggering or handling the destroy or end of a stream.

Some relevant findings:

We understand enough at this point to know that these error are not affecting user experience. In #26336 we stopped logging them, as the are clogging sentry.

We should identify and resolve the root cause, and then remove code in the error handlers that ignores these errors.

Aliceonly commented 3 months ago

hey there, my metamask always meets Premature close since it switch to a custom network. detail:https://github.com/MetaMask/metamask-extension/issues/26326 it leads my metamask can't use,cuz it always crush when open it, and lost my Secret Recovery Phrase. give any help plz, it's a fatal error. there's much important data in the extension @danjm

legobeat commented 3 months ago

others have experienced similar problems: https://github.com/mafintosh/pump/issues/25

Just noting that from my understanding pump/end-of-stream are only really compatible with legacy/v2 streams and using them with newer versions may cause undefined behavior like this due to related API changes.

AFAICT we're not utilizing those packages in runtime but only for browserify's legacy streams, though.

legobeat commented 3 months ago
  • if we use connectionStream.pipe(mux).pipe(connectionStream); instead of pipeline(connectionStream, mux, connectionStream, the error goes away, but that was changed almost 7 years ago in a PR titled "Memory leak fixes - stream and filter life cycles" https://github.com/MetaMask/metamask-extension/pull/2070

Might be something there? Looks like that reasoning behind that line-change resolving a leak might have applied to v2 streams (which was used at the time, with pump) but not for the v3 streams currently used?

github-actions[bot] commented 1 week ago

This issue has been automatically marked as stale because it has not had recent activity in the last 90 days. It will be closed in 45 days if there is no further activity. The MetaMask team intends on reviewing this issue before close, and removing the stale label if it is still a bug. We welcome new comments on this issue. We do not intend on closing issues if they report bugs that are still reproducible. Thank you for your contributions.

legobeat commented 1 week ago

not stale?