Steps to reproduce
Passing messages from a background script of an extension to a native messaging host via
Port.postMessage does not work reliable.
After some thousands of passed messages, the event handler which receives the messages stops being called. There is no exception neither on the extension background script side nor on the native side which could indicate an error.
Steps to reproduce the problem (See attachment):
- Host “nativemessagingreliability.html”
- Open, build and deploy solution “NativeMessagingReliability”
- Open Edge browser and ensure the extension “Native Messaging Reliability Test” is activated
- Navigate to hosted “nativemessagingreliability.html”
- Open F12 on the web site and optionally in extension background
- Hit “Start Native Messaging Test”
This will continuously post simlpe text messages via
browser.runtime.connectNative) to the native messaging host.
The native messaging host will then respond a simple text message to every received message. This received message is passed back to the web page.
- Usually the console output of the test should be pairs of “post count” and “recv count” which indicates all posted messages are delivered to the native messaging host and the answere gets back.
web site event listener: post count: 100 web site event listener: recv count: 100 web site event listener: post count: 200 web site event listener: recv count: 200 web site event listener: post count: 300 web site event listener: recv count: 300 ...
- After some time (and some thousands of messages passed) no more messages are delivered to the native messaging host and the output turns into:
web site event listener: post count: 5600 web site event listener: post count: 5700 web site event listener: post count: 5800 web site event listener: post count: 5900 web site event listener: post count: 6000 web site event listener: post count: 6100 ...
Note that the console log is cleared all 1000 messages to prevent memory overflows.
In my tests the error sometimes occurs after about 5000 messages, sometimes after about 10000 messages and sometimes later.
One of the edge processes leaks memory during this (see https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/13575575/), but this is not the cause for this issue as the message passed is very small and the memory usage of all affected processes keeps small.
In this state, the message from the web page is passed as far as the
background.js script which executed
nativeport.postMessage(data) without exception.
But the message handler in the native messaging host (
OnAppServiceRequestReceived) stops being called.
nativeport.onDisconnect is never called, so there is no indication of an error.
Hitting “Stop Native Messaging Test” stops firing messages. “Start Native Messaging Test” continues firing messages.
The test supports only one tab accessing the extension simultaneously.
Reloading the test web site in the browser causes the connection to the extension background to be rebuilt,
but the connection to the native messaging host is not touched.
To restart the whole test, disable and re-enable the extension, reload the page and hit “Start Native Messaging Test” again.
Comments and activity
- Microsoft Edge Team
Changed Assigned To to “James M.”
Thank you for providing this information about the issue. After thorough testing, I am unable to reproduce this problem in Edge 16299; I have attached screenshots of my repro test. Please try disabling all other browser extensions and restarting Edge to see if this fixes the problem.
The MS Edge Team
Thank you for looking at this.
I have restarted my test and it occurred after about 45000 messages.
I have attached the test result, the extensions setup (I have only installed the repo-extension) and the version number of the Edge browser (attachments with named with “45000”).
It is very random when the error occurs. Maybe the test needs to run for several minutes, or even hours, I don’t know on what this depends.
The above test was executed within a virtual machine.
I have re-run the test on a (slower) native Windows Surface device, and there the error occured after 5000 Messages in the first test run, 33000 messages in the second. In my third test the problem did not occur until 100000 messages and I aborted the test.
In one more test it stopped working after 32300 messages. For this test run I have attached screenshots (WindowsSurfaceAfter32300).
Technical Data of the Device:
Intel® Core™ i3-4020Y CPU @ 1.50GHz 1.50 GHz
4.00 GB RAM
64 Bit OS
- Microsoft Edge Team
Changed Assigned To to “email@example.com”
Changed Assigned To to “firstname.lastname@example.org”
Changed Assigned To to “Irfan A.”
Changed Status to “Confirmed”
Changed Assigned To from “Irfan A.” to “Ankit K.”
Changed Assigned To from “Ankit K.” to “Utkarsh P.”