Closed Bug 732553 Opened 8 years ago Closed 6 years ago

NS_BASE_STREAM_CLOSED in dbg-transport.js

Categories

(DevTools :: Debugger, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 24

People

(Reporter: msucan, Assigned: ochameau)

References

Details

Attachments

(2 files, 3 obsolete files)

Error Console keeps showing errors like this:

Timestamp: 02/03/2012 22:44:44
Error: [Exception... "Component returned failure code: 0x80470002 (NS_BASE_STREAM_CLOSED) [nsIOutputStream.write]"  nsresult: "0x80470002 (NS_BASE_STREAM_CLOSED)"  location: "JS frame :: chrome://global/content/devtools/dbg-transport.js :: DT_onOutputStreamReady :: line 106"  data: no]
Source File: chrome://global/content/devtools/dbg-transport.js
Line: 106

STR:

1. Open http://orion.eclipse.org/examples/textview/demo.html
2. Open the Debugger.
3. Refresh.
4. Close the Debugger.
5. Refresh.

You'll now get the NS_BASE_STREAM_CLOSED error in dbg-transport.js.
Priority: -- → P3
I am getting a loooot of those exception when debugging HTTP monitor. It's eating mobile CPU and memory a lot.

Here is updated exception message:
[JavaScript Error: "[Exception... "Component returned failure code: 0x80470002 (NS_BASE_STREAM_CLOSED) [nsIOutputStream.write]"  nsresult: "0x80470002 (NS_BASE_STREAM_CLOSED)"  location: "JS frame :: chrome://global/content/devtools/dbg-transport.js :: DT_onOutputStreamReady :: line 127"  data: no]" {file: "chrome://global/content/devtools/dbg-transport.js" line: 127}]

Do you want my STR?

Honza
(In reply to Jan Honza Odvarko from comment #1)
> I am getting a loooot of those exception when debugging HTTP monitor. It's
> eating mobile CPU and memory a lot.
> 
> Here is updated exception message:
> [JavaScript Error: "[Exception... "Component returned failure code:
> 0x80470002 (NS_BASE_STREAM_CLOSED) [nsIOutputStream.write]"  nsresult:
> "0x80470002 (NS_BASE_STREAM_CLOSED)"  location: "JS frame ::
> chrome://global/content/devtools/dbg-transport.js :: DT_onOutputStreamReady
> :: line 127"  data: no]" {file:
> "chrome://global/content/devtools/dbg-transport.js" line: 127}]
> 
> Do you want my STR?

If you don't get these when shutting down the remote connection, then certainly. It may indicate something different than what we already know.
So, in the end I found a problem in HTTP Monitor code. One of the server actors didn't detach itself from HTTP observer service and has been trying to send packets even after if the connection has been closed.

Related problem is that 'disconnect' method (which is also responsible for removing that HTTP observe listener) isn't executed by the framework if the actor is added into tabActorPool as follows:
tab.tabActorPool.addActor(actor);

It works, if I use following instead:
tab.conn.addActor(actor);

Here is the code:
https://github.com/firebug/httpmonitor/blob/master/content/httpmonitor/server/netMonitorActor.js#L209

STR:
1) Install HTTP Monitor (HTTPM) in your Nightly (run directly from source: git@github.com:firebug/httpmonitor.git)

Change this code:
    //tab.tabActorPool.addActor(actor);
    tab.conn.addActor(actor);

to:
    tab.tabActorPool.addActor(actor);
    //tab.conn.addActor(actor);

2) Set extensions.httpmonitor.serverMode to true (remoting scenario can run on one machine), You need to restart your browser after you change this pref.
3) Run Firefox, open HTTPM console (Web Developer -> HTTP Monitor)
4) The console should connect automatically (top left toolbar button should say "localhost:2929")
5) Click "Select Tab", pick a tab, reload the tab (you should see requests in HTTPM console)
6) Click "localhost:2929" and pick "Disconnect"
7) Refresh the tab again, open Firefox Error Console, you should see:

Timestamp: 8.5.2012 14:00:04
Error: [Exception... "Component returned failure code: 0x80470002 (NS_BASE_STREAM_CLOSED) [nsIOutputStream.write]"  nsresult: "0x80470002 (NS_BASE_STREAM_CLOSED)"  location: "JS frame :: chrome://global/content/devtools/dbg-transport.js :: DT_onOutputStreamReady :: line 127"  data: no]
Source File: chrome://global/content/devtools/dbg-transport.js
Line: 127

That's because "NetworkMonitorActor.disconnect" wasn't executed.

Honza
Comment on attachment 763279 [details] [diff] [review]
NS_BASE_STREAM_CLOSED in dbg-transport.js

I hit that exception many times when working on b2g support, we can't ship with such high occurence bug that make the phone unusable when you trigger it. (you have to reboot the phone)

Given my limited knowledges of debugger server code, I tried to address this issue where this exception is thrown, at DebuggerTransport level. Honza describes issues that seems to be in higher level, but I think it is also worth strengthening the low level code!
Attachment #763279 - Flags: review?(past)
Comment on attachment 763279 [details] [diff] [review]
NS_BASE_STREAM_CLOSED in dbg-transport.js

Review of attachment 763279 [details] [diff] [review]:
-----------------------------------------------------------------

(In reply to Alexandre Poirot (:ochameau) from comment #5)
> I hit that exception many times when working on b2g support, we can't ship
> with such high occurence bug that make the phone unusable when you trigger
> it. (you have to reboot the phone)

Really? I know that it wasn't causing any serious issues in desktop, but I can't remember the last time I tried it on a b2g device.

> Given my limited knowledges of debugger server code, I tried to address this
> issue where this exception is thrown, at DebuggerTransport level. Honza
> describes issues that seems to be in higher level, but I think it is also
> worth strengthening the low level code!

I think your approach is fine, but we try to make sure no unexpected error gets swallowed, so could you limit the try/catch block to the write call and rethrow the exception in cases the stream wasn't closed?
Attachment #763279 - Flags: review?(past)
Comment on attachment 763279 [details] [diff] [review]
NS_BASE_STREAM_CLOSED in dbg-transport.js

Review of attachment 763279 [details] [diff] [review]:
-----------------------------------------------------------------

::: toolkit/devtools/server/transport.js
@@ +97,5 @@
> +      this._outgoing = this._outgoing.slice(written);
> +      this._flushOutgoing();
> +    } catch(e) {
> +      if (e.result == Components.results.NS_BASE_STREAM_CLOSED) {
> +        dumpn("Connection closed in middle of a message.");

Drive by comment:  this message isn't necessarily accurate, according to https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIOutputStreamCallback.  onOuptutStreamReady is called when *either* the stream is writable or closed, so generally this error just means the stream is closed, not that it was in the middle of a message.  (We see this all the time with Marionette.)
Attachment #763279 - Attachment is obsolete: true
Attachment #764263 - Attachment is obsolete: true
Assignee: nobody → poirot.alex
Attachment #764298 - Flags: review?(past)
Attachment #764298 - Flags: review?(past) → review+
Attachment #764298 - Attachment is obsolete: true
Comment on attachment 764384 [details] [diff] [review]
NS_BASE_STREAM_CLOSED in dbg-transport.js

Carrying review after addressing the precise original request being made during the first review: scope the try/catch to the call to write.
Attachment #764384 - Flags: review+
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/903a455c5430
Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 24
Duplicate of this bug: 842972
Comment on attachment 771324 [details] [diff] [review]
b2g18 - NS_BASE_STREAM_CLOSED in dbg-transport.js

Rebased patch for b2g18.
Attachment #771324 - Attachment description: NS_BASE_STREAM_CLOSED in dbg-transport.js → b2g18 - NS_BASE_STREAM_CLOSED in dbg-transport.js
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.