Steps to reproduce
When a browser extension background page sends (a huge amount of) data with
Port.postMessage to a native messaging host all memory used by the data object is leaked.
The problem is simply and clearly reproducible doing the following (see attachment):
- Host “nativemessagingleak.html”
- Open, build and deploy solution “NativeMessagingMemoryLeak”
- Open Edge browser and ensure the extension “Native Messaging Memory Leak Test” is activated
- Navigate to hosted “nativemessagingleak.html”
- Optionally open F12 in browser and extension background
- Hit “Start Native Messaging Leak Test”
This will continuously post messages via
browser.runtime.connectNative) with a string with about 1.7 M characters each.
Observing the “MicrosoftEdge.exe” process in task manager (NOT the “MicrosoftEdgeCP.exe” processes) shows that memory usage rapidly increases.
- Hit “Stop Native Messaging Leak Test”
This stops firing the messages. The memory is not freed and the process consumes about the double amount of totally sent BLOB strings (probably 16 bit characters).
The total amount of posted data is logged into console.
When not stopping the leak test, the computer runs out of memory.
In Windows 10 Enterprise Insider Preview (Version 1703 OS Build 16251.1000, Edge 41.16251.1000.0 / 16.16251) only the “MicrosoftEdge.exe” process leaks.
When uncommenting the line “nativeport.postMessage(data);” in “background.js” no memory is leaked.
The native app which receives the data does never leak.
In Windows 10 Enterprise (Version 1703 OS Build 15063.540, Edge 40.15063.0.0/15.15063) additionally one “MicrosoftEdgeCP.exe” process leaks.
(See Bug https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13301944)
Doing exactly the same (aside from the differences in implementing a native messaging host) in Google Chrome or Firefox does not leak any memory.
There is an additional “bug” relating to native messaging:
null instead of an empty string to a native message in this example (See “App.xaml.cs” line 74) will crash the whole Edge browser.
Comments and activity
- Microsoft Edge Team
Changed Assigned To to “Steven K.”
Changed Status to “Confirmed”
Hi Dominik. Thank you for attachment! Much simpler and easier than microsoft’s SendInput demo. I am trying to understand how to write extension with native host in first place. I would much appreciate if you would share these knowledge with me. Please, be kind to reply me to email@example.com. Sorry, for posting it here. Thanks, Andrey.
- Microsoft Edge Team
Changed Status from “Confirmed”