Closed
Bug 1334068
Opened 8 years ago
Closed 8 years ago
make nsHttpChannel/HttpBaseChannel dtor thread safe
Categories
(Core :: Networking: HTTP, defect)
Core
Networking: HTTP
Tracking
()
RESOLVED
FIXED
mozilla54
Tracking | Status | |
---|---|---|
firefox54 | --- | fixed |
People
(Reporter: schien, Assigned: schien)
References
Details
(Whiteboard: [necko-active][PBg-HTTP-M1])
Attachments
(1 file, 2 obsolete files)
Several attributes in nsHttpChannel and HttpBaseChannel is not thread-safe to Release(). We should use nsMainThreadPtrHolder to make sure Release() of those XPCOM ptr are called only on main thread.
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Assignee | ||
Comment 3•8 years ago
|
||
In this WIP I only enforce the Release() for those XPCOM runs on main thread, but allows dereference to be invoked on other threads.
Comment 4•8 years ago
|
||
Unless you need to actually move the references around off the main thread it would be better not to use individual nsMainThreadPtrHandle references here. Each one dispatches a separate runnable which can be inefficient and clog up the main thread. As written I think this patch will dispatch 11 runnables if the channel is destroyed off the main thread.
Can you instead do either:
a) Create your own doomed runnable that takes ownership of the runnables and is dispatched at the main thread to release them.
b) Create a main thread object that holds the other references and just nsMainThreadPtrHandle that single object.
Updated•8 years ago
|
Whiteboard: [necko-active]
Assignee | ||
Comment 5•8 years ago
|
||
Thanks for the advice. I'll prefer (b) because people can understand the main-thread-only restriction from reading code.
Assignee | ||
Comment 6•8 years ago
|
||
After trying both (a) and (b), I'll go (a) since the modification is more reviewable.
Comment hidden (mozreview-request) |
Assignee | ||
Updated•8 years ago
|
Attachment #8830664 -
Attachment is obsolete: true
Assignee | ||
Updated•8 years ago
|
Attachment #8830665 -
Attachment is obsolete: true
![]() |
||
Comment 8•8 years ago
|
||
mozreview-review |
Comment on attachment 8833841 [details]
Bug 1334068 - proxy release main-thread-only references in nsHttpChannel and HttpBaseChannel.
https://reviewboard.mozilla.org/r/109968/#review112462
::: netwerk/protocol/http/HttpBaseChannel.cpp:2358
(Diff revision 1)
> + do_CreateInstance(NS_SECURITY_CONSOLE_MESSAGE_CONTRACTID, &rv);
> + NS_ENSURE_SUCCESS(rv, rv);
> +
> + message->SetTag(pair.first());
> + message->SetCategory(pair.second());
> + aMessages.AppendElement(message);
please add a comment why this change is needed regarding t-safety of the dtor. it's not clear to me at all.
::: netwerk/protocol/http/nsHttpChannel.h:465
(Diff revision 1)
>
> void SetDoNotTrack();
>
> private:
> + // this section is for main-thread-only object
> + // all the references need to be proxy released in main thread.
on the main thread
Attachment #8833841 -
Flags: review?(honzab.moz) → review+
Assignee | ||
Comment 9•8 years ago
|
||
mozreview-review-reply |
Comment on attachment 8833841 [details]
Bug 1334068 - proxy release main-thread-only references in nsHttpChannel and HttpBaseChannel.
https://reviewboard.mozilla.org/r/109968/#review112462
> please add a comment why this change is needed regarding t-safety of the dtor. it's not clear to me at all.
Originally security console messages are stored in an `nsCOMArray<nsISecurityConsoleMessage>`. The implementation of nsISecurityConsoleMessage is not thread-safe refcounted and I didn't find a way to move the nsCOMArray without `AddRef` to the array items. Therefore I change it to a safer type to store, which needs to delay the XPCOM creation until `TakeAllSecurityMessages`.
Add comment in next revision.
https://searchfox.org/mozilla-central/rev/afcf40f3eafd895611a839017730debb58a342a6/netwerk/protocol/http/HttpBaseChannel.h#354
> on the main thread
fixed in the next revision.
Comment hidden (mozreview-request) |
![]() |
||
Comment 11•8 years ago
|
||
(In reply to Shih-Chiang Chien [:schien] (UTC+8) (use ni? plz) from comment #9)
> Comment on attachment 8833841 [details]
> Bug 1334068 - proxy release main-thread-only references in nsHttpChannel and
> HttpBaseChannel.
>
> https://reviewboard.mozilla.org/r/109968/#review112462
>
> > please add a comment why this change is needed regarding t-safety of the dtor. it's not clear to me at all.
>
> Originally security console messages are stored in an
> `nsCOMArray<nsISecurityConsoleMessage>`. The implementation of
> nsISecurityConsoleMessage is not thread-safe refcounted and I didn't find a
> way to move the nsCOMArray without `AddRef` to the array items. Therefore I
> change it to a safer type to store, which needs to delay the XPCOM creation
> until `TakeAllSecurityMessages`.
> Add comment in next revision.
>
Thanks! Nit: maybe add MOZ_ASSERT(NS_IsMainThread()) to nsHttpChannel where appropriate around manipulation with console messages?
Comment hidden (mozreview-request) |
Assignee | ||
Comment 13•8 years ago
|
||
(In reply to Honza Bambas (:mayhemer) from comment #11)
> (In reply to Shih-Chiang Chien [:schien] (UTC+8) (use ni? plz) from comment
> #9)
> > Comment on attachment 8833841 [details]
> > Bug 1334068 - proxy release main-thread-only references in nsHttpChannel and
> > HttpBaseChannel.
> >
> > https://reviewboard.mozilla.org/r/109968/#review112462
> >
> > > please add a comment why this change is needed regarding t-safety of the dtor. it's not clear to me at all.
> >
> > Originally security console messages are stored in an
> > `nsCOMArray<nsISecurityConsoleMessage>`. The implementation of
> > nsISecurityConsoleMessage is not thread-safe refcounted and I didn't find a
> > way to move the nsCOMArray without `AddRef` to the array items. Therefore I
> > change it to a safer type to store, which needs to delay the XPCOM creation
> > until `TakeAllSecurityMessages`.
> > Add comment in next revision.
> >
>
> Thanks! Nit: maybe add MOZ_ASSERT(NS_IsMainThread()) to nsHttpChannel where
> appropriate around manipulation with console messages?
Sure, added MOZ_ASSERT(NS_IsMainThread()) in `HttpBaseChannel::TakeAllSecurityMessages` and `HttpBaseChannel::AddSecurityMessage`.
Comment 14•8 years ago
|
||
Pushed by schien@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/8208dedaa305
proxy release main-thread-only references in nsHttpChannel and HttpBaseChannel. r=mayhemer
Comment 15•8 years ago
|
||
bugherder |
Status: NEW → RESOLVED
Closed: 8 years ago
status-firefox54:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
Assignee | ||
Updated•8 years ago
|
Whiteboard: [necko-active] → [necko-active][PBg-HTTP-M1]
You need to log in
before you can comment on or make changes to this bug.
Description
•