cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: scp maxing the CPU

From: James Housley <jim_at_thehousleys.net>
Date: Tue, 14 Nov 2006 12:17:27 -0500

On Nov 14, 2006, at 11:30 AM, Gisle Vanem wrote:

> "Daniel Stenberg" <daniel_at_haxx.se> wrote:
>
>>> I'll take a look when I have the time (at the weekend?).
>> Ouch. I have a very interesting way to max out the memory usage
>> beyond unreal:
>> curl scp://localhost:80/helllo
>> With an ordinary apache http server running on port 80,
>> libssh2_session_startup() gets stuck and initially it spent a lot
>> of CPU but primarily it ate some 800MB of ram before I could break
>> it.
>
> Digging into libssh2, I found the same thing;
> libssh2_session_startup() calls
> libssh2_banner_receive() (in session.c). This function never
> completes, but gets stuck in the while-loop waiting for the banner.
> I'm sure the test-server
> is running ssh (from what I can see from nmap).
>
> The code:
> ret = recv(session->socket_fd, &c, 1, LIBSSH2_SOCKET_RECV_FLAGS
> (session));
>
> if (ret < 0) {
> #ifdef WIN32
> switch (WSAGetLastError()) {
> case WSAEWOULDBLOCK:
> errno = EAGAIN;
> break;
> case WSAENOTSOCK:
> errno = EBADF;
> break;
> case WSAENOTCONN:
> case WSAECONNABORTED:
> errno = ENOTCONN;
> break;
>
> The socket is non-blocking. Thus WSAGetLastError() returns
> WSAEWOULDBLOCK for
> some time. Then recv() becomes blocking (!) . The curious thing is
> that it doesn't return WSAENOTCONN after the socket enters
> CLOSE_WAIT. Even closing the socket from tcpview (a netstat-like
> program) doesn't cause recv() to return...

I don't have access to any computers running Windows, but it does
look like there is a small problem with the above code, and the
similar code in packet.c Only 4 error codes are checked in the
switch statement. Are those the only 4 that are valid for recv(2)?
My guess is that errno should be set to some value before the switch
statement or a default: case needs to be added.

Jim

--
/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
  X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
jeh@FreeBSD.org      http://www.FreeBSD.org     The Power to Serve
jim@TheHousleys.Net  http://www.TheHousleys.net
---------------------------------------------------------------------
Progress (n) : What led from smart users in front of dumb terminals to
dumb users in front of smart terminals.
Received on 2006-11-14