You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2001/10/25 15:56:02 UTC

DO NOT REPLY [Bug 4418] - Race Condition in net.serversocketfactory.java

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4418>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4418

Race Condition in net.serversocketfactory.java





------- Additional Comments From Pete.Sage@gefanuc.com  2001-10-25 06:56 -------
    public static ServerSocketFactory getDefault () {
        //
        // optimize typical case:  no synch needed
        //

        if (theFactory == null) {
            synchronized (ServerSocketFactory.class) {
                //
                // Different implementations of this method could
                // work rather differently.  For example, driving
                // this from a system property, or using a different
                // implementation than JavaSoft's.
                //

                theFactory = new DefaultServerSocketFactory ();
            }
        }

this code is incorrect, as two threads could perform the check and create a new 
DefaultServerSocketFactory.  Change the code to something like

    public static ServerSocketFactory getDefault () {
        //
        // optimize typical case:  no synch needed
        //

        if (theFactory == null) {
            synchronized (ServerSocketFactory.class) {
                //
                // Different implementations of this method could
                // work rather differently.  For example, driving
                // this from a system property, or using a different
                // implementation than JavaSoft's.
                //

                //***** Prevent two threads from doing this after unsychronized 
check!
                if (theFactory == NULL)
                theFactory = new DefaultServerSocketFactory ();
            }
        }