Closed
Bug 925831
Opened 11 years ago
Closed 11 years ago
Warn when doing synchronous IO using NetUtil.asyncCopy
Categories
(Core :: XPCOM, defect)
Tracking
()
RESOLVED
INCOMPLETE
People
(Reporter: taras.mozilla, Assigned: Yoric)
References
Details
(Keywords: dev-doc-needed, Whiteboard: [Async][Snappy])
Attachments
(2 files)
(deleted),
patch
|
Details | Diff | Splinter Review | |
(deleted),
patch
|
Details | Diff | Splinter Review |
NetUtil.asyncCopy should print a big fat warning when using non-blocking streams. Adding checks around http://dxr.mozilla.org/mozilla-central/source/xpcom/io/nsStreamUtils.cpp#l253 might be sufficient, assuming interfaces dont lie about being async
Reporter | ||
Comment 1•11 years ago
|
||
Currently there is a lot of misinformed asyncCopy usage, eg https://bugzilla.mozilla.org/show_bug.cgi?id=562674
Summary: Warn that using NetUtil.asyncCopy is usually a lie → Warn when doing synchronous IO using NetUtil.asyncCopy
Reporter | ||
Comment 2•11 years ago
|
||
Mike or David, one of you guys should own fixing this
Assignee | ||
Comment 3•11 years ago
|
||
We could do it in JS or in C++. I am inclined to say JS, using Deprecated.jsm, because this will let devs find the culprit more easily.
Whiteboard: [Async][Snappy]
Reporter | ||
Comment 4•11 years ago
|
||
We should do this in C++, because this pattern is used in C++ too. Technically it's not deprecated since os.file isn't a complete alternative(eg it doesn't copy from network streams, zips)
Assignee | ||
Updated•11 years ago
|
Assignee: nobody → dteller
Assignee | ||
Comment 5•11 years ago
|
||
I believe that we are going to have lots of false positives/negatives on that one.
Nothing ensures that |nsIAsync{Input, Output}Stream| implementations don't block the main thread, just as nothing ensures that |isNonBlocking()| streams don't block the main thread. I'll write a first version, but I suspect that we're going to need some fine-tuning.
Side-note: Deprecated.jsm doesn't mean that OS.File can replace it, just that devs should find a better implementation. I'd be inclined to have both the C++ version to get the warning and the JS version as it prints the stack.
Assignee | ||
Comment 6•11 years ago
|
||
Attachment #816514 -
Flags: review?(mh+mozilla)
Assignee | ||
Comment 7•11 years ago
|
||
We'll also need to update the documentation of NetUtil.asyncCopy, which gives an anti-pattern example.
Keywords: dev-doc-needed
Assignee | ||
Comment 8•11 years ago
|
||
Adding a warning also at JS level.
This is essentially the same warning as in C++, except it is conditioned upon "devtools.errorconsole.deprecation_warnings" instead of DEBUG and it also displays the JS stack.
Attachment #816515 -
Flags: review?(nfroyd)
Updated•11 years ago
|
Attachment #816514 -
Flags: review?(mh+mozilla) → review?(benjamin)
Assignee | ||
Comment 9•11 years ago
|
||
Looking at the code more carefully, I have the impression that NS_AsyncCopy actually dispatches every call to read or write off the main thread (argument |target|), regardless of whether the thread is sync or async - that's methods DoCopy() and Process() in nsAStreamCopier and its subclasses. Also, closing seems to be done OMT.
If I'm right, I can't think of any meaningful warning we could add in nsStreamUtils.cpp.
Taras, am I missing something?
Flags: needinfo?(taras.mozilla)
Assignee | ||
Comment 10•11 years ago
|
||
Comment on attachment 816514 [details] [diff] [review]
Warn when calling NS_AsyncCopy with a non-nsIAsync*Stream.
Canceling r? until I have investigated the underlying issue.
Attachment #816514 -
Flags: review?(benjamin)
Assignee | ||
Comment 11•11 years ago
|
||
Comment on attachment 816515 [details] [diff] [review]
Warn when calling NetUtil.asyncCopy with a non-nsIAsync*Stream.
Canceling r? until I have investigated the underlying issue.
Attachment #816515 -
Flags: review?(nfroyd)
Assignee | ||
Comment 12•11 years ago
|
||
Calling NetUtil.asyncCopy on a (buffered) nsIJARInputStream has the following effect:
- it fills the buffer onces on the main thread during the call to |ioUtil.inputStreamIsBuffered|;
- the subsequent I/O operations are performed off the main thread.
Note that we cannot create it on an unbuffered nsIJARInputStream (see bug 927366).
Assignee | ||
Comment 13•11 years ago
|
||
Taking care of that single main thread I/O in bug 927407.
Reporter | ||
Comment 14•11 years ago
|
||
> Looking at the code more carefully, I have the impression that NS_AsyncCopy
> actually dispatches every call to read or write off the main thread
> (argument |target|), regardless of whether the thread is sync or async -
> that's methods DoCopy() and Process() in nsAStreamCopier and its subclasses.
> Also, closing seems to be done OMT.
>
> If I'm right, I can't think of any meaningful warning we could add in
> nsStreamUtils.cpp.
>
> Taras, am I missing something?
Sounds like you found some main thread IO and some evidence that most IO is off main thread. Happy to hear, this wasn't as bad as I thought.
Flags: needinfo?(taras.mozilla)
Assignee | ||
Comment 15•11 years ago
|
||
Doesn't seem that there is much we can do here. Closing the bug.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → INCOMPLETE
You need to log in
before you can comment on or make changes to this bug.
Description
•