Bug 16473 - [3.4] ServerSocket accept() leaks file descriptors
Summary: [3.4] ServerSocket accept() leaks file descriptors
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgcj (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: 3.4.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-11 16:12 UTC by Bryce McKinlay
Modified: 2004-10-30 21:09 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.0.0
Known to fail: 3.4.0 3.4.1
Last reconfirmed: 2004-07-11 16:15:21


Attachments
Test case (650 bytes, text/plain)
2004-07-11 16:39 UTC, Bryce McKinlay
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bryce McKinlay 2004-07-11 16:12:10 UTC
As reported by Eric Wong:

In version 3.4.0/1, ServerSocket.accept() creates a
new Socket() and then in the process invoke
Socket.getImpl(), which goes something like this:

-----
SocketImpl getImpl() throws SocketException
    try
      {
        if (!implCreated)
          {
            impl.create(true);
            implCreated = true;
          }
      }
    catch (IOException e)
      {
        throw new SocketException(e.getMessage());
      }

    return impl;
-----

But create(true) alone will cause
natPlainSocketImplPosix.cc (depending on the platform)
to create a fresh yet never-been-used socket
descriptor. As a result, lsof will show:


>> socktest 31812 root 8u  sock 0,0 1364355 can't
identify protocol

So each ServerSocket.accept() call will generate
additional descriptor until we get EMFILE error ("Too
many open files").
Comment 1 Bryce McKinlay 2004-07-11 16:15:20 UTC
I can confirm Eric's report.
Comment 2 Bryce McKinlay 2004-07-11 16:39:52 UTC
Created attachment 6721 [details]
Test case
Comment 3 GCC Commits 2004-07-11 16:42:34 UTC
Subject: Bug 16473

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	bryce@gcc.gnu.org	2004-07-11 16:42:29

Modified files:
	libjava        : ChangeLog 
	libjava/java/net: ServerSocket.java Socket.java 

Log message:
	2004-07-11  Michael Koch  <konqueror@gmx.de>
	
	PR libgcj/16473
	* java/net/ServerSocket.java (accept): Don't create two client
	sockets when accepting connections.
	* java/net/Socket.java (impl): Made package-private.
	(implCreated): Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.2562.2.18&r2=1.2562.2.19
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/net/ServerSocket.java.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.34.4.1&r2=1.34.4.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/net/Socket.java.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.33.4.1&r2=1.33.4.2

Comment 4 Bryce McKinlay 2004-07-11 16:42:50 UTC
Fix checked in.