Closed Bug 23778 Opened 26 years ago Closed 26 years ago

[DOGFOOD]100% CPU usage when using POP

Categories

(MailNews Core :: Networking, defect, P3)

Other
Other
defect

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: alecf, Assigned: warrensomebody)

References

Details

(Whiteboard: [PDT+])

Attachments

(2 files)

I'm using POP on linux to download mail from my ISP... whenever I click get new mail, my CPU usage goes to 100% and stays there... it seems to be looping here: (gdb) where #0 0x401a3efa in PR_Poll (pds=0x8598248, npds=3, timeout=35000) at ptio.c:3666 #1 0x40b1be55 in nsSocketTransportService::Run (this=0x8598210) at nsSocketTransportService.cpp:436 #2 0x4011b345 in nsThread::Main (arg=0x8598590) at nsThread.cpp:83 #3 0x401a58fb in _pt_root (arg=0x85985a8) at ptthread.c:157 #4 0x401baeca in pthread_start_thread (arg=0xbf5ffe60) at manager.c:213 this is just one place the thread is, but it's always in nsSocketTransport::Run() With netstat it looks like the socket has been closed: Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 nefarious.mcom.com:1623 cluster.ispchanne:pop-3 CLOSE_WAIT 15302/mozilla-bin the server is an "InterMail" server, whatever that is: telnet pop3.ispchannel.com pop-3 Trying 24.142.63.7... Connected to pop3.ispchannel.com. Escape character is '^]'. +OK InterMail POP3 server ready. It hangs with both leave on server on and off.
oops, I didn't mean hangs, I meant it goes to 100% cpu - the browser is still usable (I'm using it right now in this state) but it's taking up all my CPU time!)
adding warren to CC because he might know what's going on. here's another stack trace: gdb) where 10 #0 0x401bd968 in __pthread_getspecific (key=0) at specific.c:125 #1 0x401a63c6 in ?? () from /home1/alecf/seamonkey/mozilla/dist/bin/libnspr3.so #2 0x40187c00 in ?? () from /home1/alecf/seamonkey/mozilla/dist/bin/libnspr3.so #3 0x40118a25 in nsAutoLockBase::nsAutoLockBase (this=0xbf5ffb70, addr=0x89b2248, type=eAutoCMonitor) at nsAutoLock.cpp:196 #4 0x4010853f in nsPipe::nsPipeInputStream::Fill (this=0x89b2250) at ../../dist/include/nsAutoLock.h:244 #5 0x40108158 in nsPipe::nsPipeInputStream::ReadSegments (this=0x89b2250, writer=0x4052e6bc <nsWriteToSocket(void *, char const *, unsigned int, unsigned int, unsigned int *)>, closure=0x80ac988, count=8192, readCount=0xbf5ffc1c) at nsPipe2.cpp:376 #6 0x4052ebe9 in nsSocketTransport::doWriteFromBuffer (this=0x89b2070, aCount=0xbf5ffc1c) at nsSocketTransport.cpp:1099 #7 0x4052ea18 in nsSocketTransport::doWrite (this=0x89b2070, aSelectFlags=32) at nsSocketTransport.cpp:1012 #8 0x4052db29 in nsSocketTransport::Process (this=0x89b2070, aSelectFlags=32) at nsSocketTransport.cpp:521 #9 0x40531eb0 in nsSocketTransportService::Run (this=0x89b1b50) at nsSocketTransportService.cpp:467 (More stack frames follow...) ooops, that was short. Here's another one I just captured: (gdb) where #0 0x401be345 in __pthread_unlock (lock=0x8052908) at spinlock.c:108 #1 0x401bbb5f in __pthread_mutex_unlock (mutex=0x80528f8) at mutex.c:126 #2 0x4019c8d1 in PR_Unlock (lock=0x80528f8) at ptsynch.c:192 #3 0x40186da7 in PR_CEnterMonitor (address=0x89b2248) at prcmon.c:304 #4 0x401079af in nsPipe::GetReadSegment (this=0x89b2248, segmentLogicalOffset=0, resultSegment=0xbf5ffbb8, resultSegmentLen=0xbf5ffbbc) at ../../dist/include/nsAutoLock.h:248 #5 0x401080ba in nsPipe::nsPipeInputStream::ReadSegments (this=0x89b2250, writer=0x4052e6bc <nsWriteToSocket(void *, char const *, unsigned int, unsigned int, unsigned int *)>, closure=0x80ac988, count=8192, readCount=0xbf5ffc1c) at nsPipe2.cpp:363 #6 0x4052ebe9 in nsSocketTransport::doWriteFromBuffer (this=0x89b2070, aCount=0xbf5ffc1c) at nsSocketTransport.cpp:1099 #7 0x4052ea18 in nsSocketTransport::doWrite (this=0x89b2070, aSelectFlags=32) at nsSocketTransport.cpp:1012 #8 0x4052db29 in nsSocketTransport::Process (this=0x89b2070, aSelectFlags=32) at nsSocketTransport.cpp:521 #9 0x40531eb0 in nsSocketTransportService::Run (this=0x89b1b50) at nsSocketTransportService.cpp:467 #10 0x4011b345 in nsThread::Main (arg=0x89b1cb0) at nsThread.cpp:83 #11 0x401a58fb in _pt_root (arg=0x89b1cc8) at ptthread.c:157 #12 0x401baeca in pthread_start_thread (arg=0xbf5ffe60) at manager.c:213
Status: NEW → ASSIGNED
Target Milestone: M13
Sure enough, I did see the cpu peg away. Warren, what do we do to shutdown/close a socket in the new world?
QA Contact: lchiang → esther
Warren, I think this is your bug. I don't think I can do much about it from the mail protocol side. When the remote server disconnect us we don't close down the connection until we shutdown the nsSocketTransportService. This happens to pop3 each time we get new messages. It happens on news server too. Also, on imap when server times out. I'll keep poking around in nsSocketTransport and see if I can find a way to resolve it.
Assignee: jefft → warren
Status: ASSIGNED → NEW
Off to warren ...
nominate for dogfood. This is driving me crazy - I can't compile while my CPU is at 100%! I'm also noticing that the messages don't get incorporated until I visit another folder and then return to the inbox.
Summary: 100% CPU usage when using POP → [DOGFOOD]100% CPU usage when using POP
Whiteboard: [PDT+]
PDT+
I think I have a fix for this, but I need someone to review it (maybe Jud, WTC or Alec). I'll add the fix as an attachment. But here's what I think is happening... On Linux, PR_Poll returns PR_POLL_HUP in the out_flags, but it seems that Windows does not. (And the note at the bottom of http://msdn.microsoft.com/library/ddkdoc/ntddk/native/ddk/ng1/src/apendixb_21.h tm confirms POLLHUP isn't supported on Windows.) nsSocketTransportService::Run calls nsSocketTransport::Process with the out_flags, but Process only deals with PR_POLL_EXCEPT. This causes us to not notice that the server hung up, and we sit in the Write state repeatedly trying to write 0 bytes out(!). My changes makes us not only check for PR_POLL_EXCEPT and PR_POLL_HUP, but also PR_POLL_ERR and PR_POLL_NVAL which we're also ignoring, and I suspect could cause a similar problem. When any of these are detected, we end up canceling pending read and write operations. This patch really should be reviewed by Rick Potts, but he's away on vaction for 2 weeks. In the mean time, this seems to fix the spin.
The change looks good to me. Couple comments. Maybe change the PR_LOG output that is fired when we fall into the exception in order to reflect something more general occurred. This is a good fix. It'll allow us to capture other error conditions (which I need to be doing for another bug).
What are the values of the in_flags and out_flags of PR_Poll when this tight spin occurs? When the peer closes a socket connection, the socket on our side should become readable, and the next read should return 0 bytes. However, if your in_flags does not contain PR_POLL_READ, PR_Poll cannot report PR_POLL_READ in the out_flags. Perhaps this is why Linux's poll() has to resort to using POLLHUP to convey this information. warren@netscape.com wrote: > This causes us to not notice that the server hung up, and > we sit in the Write state repeatedly trying to write 0 bytes out(!). Why do you want to write 0 bytes out? When you write to a closed socket connection, the standard Unix behavior is to send the process a SIGPIPE signal. Since NSPR handles SIGPIPE, the write() or send() system call should fail with EPIPE. Apparently this is not happening, otherwise you would have noticed the write failure and exited the loop. So I guess it might have to do with your writing 0 bytes. Maybe writing 0 bytes to a closed socket connection doesn't cause Linux to send you a SIGPIPE. I'm afraid that I'm not familiar enough with the netwerk code to review your patch. It looks good to me, but I suspect that you may also need to address the write 0 bytes issue.
I'm testing this patch now... why write 0 bytes out at all? i.e. why bother making an expensive system call if it doesn't do anything?
this patch works great on linux! I can actually read POP reasonably now!
ok, linux works with NNTP, POP, IMAP and SMTP next stop: macintosh.
Re. writing 0 bytes: We're not doing this explicitly, the application seems to. I guess we could check for it and bypass the PR_Write call though. Re. next stop Macintosh: What's up with that? Is it broken? File a new bug. I'm going to check this fix in.
The fix is in. I don't think it will affect anything besides linux since linux is the only platform that returns HUP.
Status: NEW → RESOLVED
Closed: 26 years ago
Resolution: --- → FIXED
next stop is TESTING macintosh
Sorry, but I backed this change out, and it seems to have fixed the bloat test problem we were seeing on linux. Now I'm not sure how to handle the problem.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
We should find out who's writing 0 bytes out.
oh mama! I hate to bring this up now. But I've noticed (first noticed it about 6 months ago) that we constantly (apparently only when the socket transport is in "use") read and write a single byte with the ascii value '8' (eight). I'm watching this happen using a tcp trace utility (www.traceplus.com). I don't think I've tried watching our PR_Read/Write calls to see if the socket transport is indeed the one doing it. But, I don't know who else could be :-/. If someone deems this info irrelevent to this bug, forget that I said anything. Although at some point we're going to have to figure out what's going on.
Second patch checked into tip and branch.
Status: REOPENED → RESOLVED
Closed: 26 years ago → 26 years ago
Resolution: --- → FIXED
alecf, how can I test this. My POP account downloads the messages quickly (I don't have more than 10) finishes and then I can use the app. This is using the 2000012401 build on my linux system, so I went back to a build before the patch (1/20/00) and that worked as I mentioned above. Please let me know what I need to do to test this.
you can run a CPU monitor like "xload" and see if the CPU load starts climbing after the POP operation starts...
Using linux build 2000012520m13 this is fixed. To test I ran xload while accessing my POP account, Get Msg did not cause the indicator to climb more than 1/2 way up. I then downloaded the 1/20 build and ran the same test (to see the problem), sure enough the indicator climbed up to the top and over. So I will verify this based on my comparison test. alecf, if you still see the problem please reopen.
Status: RESOLVED → VERIFIED
thanks for the extensive testing!
*** Bug 22166 has been marked as a duplicate of this bug. ***
Product: MailNews → Core
Product: Core → MailNews Core
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: