Closed Bug 1220012 Opened 10 years ago Closed 10 years ago

Leak nsPipe from GeckoDriver.mozBrowserClose

Categories

(Remote Protocol :: Marionette, defect, P2)

defect

Tracking

(firefox45 fixed, b2g-v2.2 affected, b2g-v2.5 fixed, b2g-master fixed)

RESOLVED FIXED
mozilla45
Tracking Status
firefox45 --- fixed
b2g-v2.2 --- affected
b2g-v2.5 --- fixed
b2g-master --- fixed

People

(Reporter: ting, Unassigned)

References

Details

(Keywords: pi-marionette-server)

Attachments

(1 file)

Two nsPipe are created for the input/ouput stream in MarionetteServer.onSocketAccepted(). After MarionetteServer.onConnectionClosed() gets called, the connection (Dispatcher) is still referenced by leaked GeckoDriver.mozBrowserClose. Now mozBrowserClose is removed when enter GeckoDriver.receiveMessage(), but probably it should be cleared before running any command.
(In reply to Ting-Yu Chou [:ting] from comment #0) > Now mozBrowserClose is removed when enter GeckoDriver.receiveMessage(), but > probably it should be cleared before running any command. Hmm, it should be all right to clear the mozBrowserClose in receiveMessage() as it will receive the command's respone/error message from listener. Am double checking.
(In reply to Ting-Yu Chou [:ting] from comment #1) > Hmm, it should be all right to clear the mozBrowserClose in receiveMessage() > as it will receive the command's respone/error message from listener. Am > double checking. Note that receiveMessage is only called when the listener sends a message back to the driver; not at any other time.
Listener does send message (Marionette:ok,error,done) back to the driver, just driver does not listen to it (bug 1107706 part 5 made the change). I'd like to move the code removing mozBrowserClose from GeckoDriver.receiveMessage() to GeckoDriver.responseCompleted(). How do you think?
Flags: needinfo?(ato)
Maybe we should simply add the messages back, so driver will receive the them. GeckoDriver.responseCompleted() is not always called, e.g., when it's out of sync.
(In reply to Ting-Yu Chou [:ting] from comment #4) > Maybe we should simply add the messages back, so driver will receive the > them. GeckoDriver.responseCompleted() is not always called, e.g., when it's > out of sync. Correction: Maybe we should simply add the message listeners back, so driver will receive the messages.
Attached patch patch v1Splinter Review
Is now testing the patch on device, will check on Monday.
Comment on attachment 8681119 [details] [diff] [review] patch v1 The leak is not observed after running ~1.5h MTBF with the patch.
Flags: needinfo?(ato)
Attachment #8681119 - Flags: review?(ato)
(In reply to Ting-Yu Chou [:ting] from comment #7) > Comment on attachment 8681119 [details] [diff] [review] > patch v1 > > The leak is not observed after running ~1.5h MTBF with the patch. It's monday morning, and still don't see the leaks.
OS: Unspecified → Gonk (Firefox OS)
Priority: -- → P2
Hardware: Unspecified → ARM
David and Andreas, please help to review patch in comment 7. Many thanks.
Flags: needinfo?(dburns)
Flags: needinfo?(ato)
Sorry for my late response to this bug, but I've been travelling to Japan. (In reply to Ting-Yu Chou [:ting] from comment #0) > Two nsPipe are created for the input/ouput stream in > MarionetteServer.onSocketAccepted(). After > MarionetteServer.onConnectionClosed() gets called, the connection > (Dispatcher) is still referenced by leaked GeckoDriver.mozBrowserClose. > > Now mozBrowserClose is removed when enter GeckoDriver.receiveMessage(), but > probably it should be cleared before running any command. Can you please help me understand what reference prevents the nsPipe from being cleaned up? I get that Dispatcher gets an instance of DebuggerTransport, which in turn encapsulates the input and output streams. However, the Dispatcher isn't passed to GeckoDriver. From what I can tell, MarionetteServer#onConnectionClosed attempts to clean up the Dispatcher by deleting its reference to it form MarionetteServer#conns: delete this.conns[id]; Is what you're saying that as long as GeckoDriver keeps an active event listener, mozbrowserclose in this case, it will never be cleaned up? But how does GeckoDriver reference Dispatcher? If we want to clean up the GeckoDriver#mozBrowserClose event listener when we close the connection (MarionetteServer#onConnectionClosed) I feel removing it in GeckoDriver#receiveMessage is the wrong solution. Wouldn't this be better suited for a shutdown/cleanup method in GeckoDriver that we call when we want to deconstruct Dispatcher from MarionetteServer?
Flags: needinfo?(dburns)
Flags: needinfo?(ato)
Flags: needinfo?(janus926)
OS: Gonk (Firefox OS) → All
Hardware: ARM → All
(In reply to Andreas Tolfsen (:ato) from comment #10) > Is what you're saying that as long as GeckoDriver keeps an active event > listener, mozbrowserclose in this case, it will never be cleaned up? But > how does GeckoDriver reference Dispatcher? GeckoDriver.emulator.send references to Dispatcher.send, which keeps the Dispatcher instance alive and Dispatcher.conn points to the DebuggerTransport. Also GeckoDriver is leaked to window through mozbrowserclose event listener. > > If we want to clean up the GeckoDriver#mozBrowserClose event listener when > we close the connection (MarionetteServer#onConnectionClosed) I feel > removing it in GeckoDriver#receiveMessage is the wrong solution. Wouldn't > this be better suited for a shutdown/cleanup method in GeckoDriver that we > call when we want to deconstruct Dispatcher from MarionetteServer? In that way, the listener could be added many times but remove just once. Note the listener is added for commands actionChain, multiAction, clickElement, and singleTap, that's why I remove it in GeckoDriver.receiveMessage when the command is done.
Flags: needinfo?(janus926)
(In reply to Ting-Yu Chou [:ting] from comment #11) > In that way, the listener could be added many times but remove just once. > Note the listener is added for commands actionChain, multiAction, > clickElement, and singleTap, that's why I remove it in > GeckoDriver.receiveMessage when the command is done. I've gone over this three times, but I still don't get it. Why do we need to remove mozbrowserclose only when ok, done, or error comes back and not otherwise?
(In reply to Andreas Tolfsen (:ato) from comment #12) > (In reply to Ting-Yu Chou [:ting] from comment #11) > > In that way, the listener could be added many times but remove just once. > > Note the listener is added for commands actionChain, multiAction, > > clickElement, and singleTap, that's why I remove it in > > GeckoDriver.receiveMessage when the command is done. > > I've gone over this three times, but I still don't get it. Why do we need > to remove mozbrowserclose only when ok, done, or error comes back and not > otherwise? Because from what I can see, ok, done, or error denotes the command is finished. And the listener is added before doing the commands, so remove it when the command gets done. It's also OK if you think we should just roll back to the code before refactoring, which removes the listener whenever receives a message.
Comment on attachment 8681119 [details] [diff] [review] patch v1 Review of attachment 8681119 [details] [diff] [review]: ----------------------------------------------------------------- (In reply to Ting-Yu Chou [:ting] from comment #13) > Because from what I can see, ok, done, or error denotes the command is > finished. And the listener is added before doing the commands, so remove it > when the command gets done. OK, thanks for all the explanations. This patch changes the mozBrowserClose check from being run on every message from the listener to only on ok, done, and error. Provided this is fine, I see no reason to integrate this patch as it is.
Attachment #8681119 - Flags: review?(ato) → review+
Keywords: checkin-needed
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla45
Comment on attachment 8681119 [details] [diff] [review] patch v1 NOTE: Please see https://wiki.mozilla.org/Release_Management/B2G_Landing to better understand the B2G approval process and landings. [Approval Request Comment] Bug caused by (feature/regressing bug #): 1107706 User impact if declined: memory leaks from using marionette Testing completed: marionette unit tests on try Risk to taking this patch (and alternatives if risky): low as it just removes listeners String or UUID changes made by this patch: none
Attachment #8681119 - Flags: approval‑mozilla‑b2g44?
Mahe, please help to approve this uplift request. Thanks.
Flags: needinfo?(mpotharaju)
Comment on attachment 8681119 [details] [diff] [review] patch v1 Approved for 2.5 uplifts. Thanks
Flags: needinfo?(mpotharaju)
Attachment #8681119 - Flags: approval‑mozilla‑b2g44? → approval‑mozilla‑b2g44+
Product: Testing → Remote Protocol
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: