tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sexton, George" <gsex...@mhsoftware.com>
Subject RE: Simultaneous request from same IP
Date Mon, 16 Dec 2002 19:43:41 GMT
Let us apply Occam's Razor here. You probably haven't heard of it so I will
repeat it here and show the application to your situation. Quite simply, it
says that when you have two competing theories to explain something, the
simplest theory is usually the correct one.

So, let's apply this:

Theory 1 proposed by you: Tomcat is horribly broken, and unthread safe. It
has major problems processing more than one simultaneous request to a
servlet and no one but you has noticed this. Hundreds or thousands of
developers and applications have not heretofore brought this to light, but
you have.

Theory 2 (proposed by several people on the list): Your application is not
thread safe, and is broken.

Occam's Razor says that your program is broken, and you need to fix it.

George Sexton
MH Software, Inc.
Voice: 303 438 9585
http://www.mhsoftware.com


-----Original Message-----
From: Chris Bick [mailto:cbick@wurldmedia.com]
Sent: 16 December, 2002 11:26 AM
To: Tomcat Users List
Subject: RE: Simultaneous request from same IP


TrafficCop is thread safe because add() is synchronized.  Regardless if
trafficcop is thread safe or not the values that I get from
HttpServletRequest should not be the same.  If I were to take TrafficCop
out of the servlet, I would get the same results in my servlet.  I guess
what I am saying is that TrafficCop should have nothing to do with the
behavior that I am seeing inside the servlet. Right?

-cb

-----Original Message-----
From: Tim Funk [mailto:funkman@joedog.org]
Sent: Monday, December 16, 2002 1:05 PM
To: Tomcat Users List
Subject: Re: Simultaneous request from same IP

But the same trafficCop instance is being used at the same time for 2
differnt requests.

The trafficCop  object has a method called add() which  (seems to) acts
on instance variables inside of the trafficCop  object. This makes the
trafficCop object not thread safe.

-Tim

Chris Bick wrote:
> Why does that effect the HttpServletRequest object?  If you look at
the
> code it evaluates the header and query string values before I access
the
> trafficcop object.  I will give it a try.
>
> -cb
>
> -----Original Message-----
> From: Tim Funk [mailto:funkman@joedog.org]
> Sent: Monday, December 16, 2002 12:40 PM
> To: Tomcat Users List
> Subject: Re: Simultaneous request from same IP
>
> Is TrafficCop.java thread safe?
>
> If not - that is your problem. Both requests are using the same
> trafficCop instance.
>
> -Tim
>
> Chris Bick wrote:
>
>>No offense taken.  I still can't believe that this problem may exist.
>>If you can find a problem with my code, that would be much easy then
>>getting a fix into tomcat.
>>
>>Thanks,
>>-cb
>>
>>
>>
>>import javax.servlet.*;
>>import javax.servlet.http.*;
>>import java.io.*;
>>import java.util.*;
>>
>>import java.net.*;
>>
>>
>>/**
>> * <p>Title: </p>
>> * <p>Description: </p>
>> * <p>Copyright: Copyright (c) 2002</p>
>> * <p>Company: </p>
>> * @author not attributable
>> * @version 1.0
>> */
>>
>>public class TrafficCopServlet extends HttpServlet {
>>  private static final String CONTENT_TYPE_XML = "text/xml";
>>  private static final String CONTENT_TYPE_HTML = "text/html";
>>  /**@todo set DTD*/
>>  private static final String DOC_TYPE = null;
>>  //Initialize global variables
>>
>>  private TrafficCop trafficCop;
>>  public void init() throws ServletException
>>  {
>>    trafficCop = new TrafficCop(false);
>>  }
>>
>>  //Process the HTTP Get request
>>  public void doGet(HttpServletRequest request, HttpServletResponse
>>response) throws ServletException, IOException {
>>    PrintWriter out = response.getWriter();
>>
>>    try
>>    {
>>      if (request.getRequestURI().endsWith("/insert"))
>>      {
>>        response.setContentType(CONTENT_TYPE_XML);
>>        out.println("<?xml version=\"1.0\"?>");
>>
>>        String pcpVersion = request.getHeader("PCP-Client-Version");
>>        String clientId = request.getHeader("PCP-Client-ID");
>>        String listenIP = request.getHeader("Listen-IP");
>>        String behindFirewall = request.getHeader("Behind-Firewall");
>>
>>        String urn = request.getQueryString();
>>
>>        synchronized(System.out)
>>        {
>>        System.out.println("URN:" + request.getQueryString());
>>        System.out.println(request.getHeader("Listen-IP"));
>>        }
>>        //System.out.println("Listen-IP:" + listenIP);
>>
>>        if (pcpVersion == null || clientId == null ||
>>            listenIP == null || behindFirewall == null ||
>>            urn == null)
>>        {
>>          String error = "<error>Bad Headers</error>";
>>          out.println(error);
>>          return;
>>        }
>>
>>        String xml = trafficCop.add(urn,new
>>URL(null,"pcp://"+listenIP,new Handler()), new
>>Boolean(behindFirewall).booleanValue(), 0);
>>
>>        System.out.println(xml);
>>        out.println(xml);
>>      }
>>      else if (request.getRequestURI().endsWith("/delete"))
>>      {
>>        response.setContentType(CONTENT_TYPE_XML);
>>        out.println("<?xml version=\"1.0\"?>");
>>
>>        String clientId = request.getHeader("PCP-Client-ID");
>>        String sessionId = request.getHeader("My-Session-ID");
>>        String deleteSessionId =
>
> request.getHeader("Delete-Session-ID");
>
>>         String listenIP = request.getHeader("Listen-IP");
>>        String behindFirewall = request.getHeader("Behind-Firewall");
>>
>>        String completed = request.getHeader("Completed");
>>        String elapsedTime = request.getHeader("Elapsed-Time");
>>        String avgDownstream =
>
> request.getHeader("Average-Downstream");
>
>>        String urn = request.getQueryString();
>>
>>        if (clientId == null || sessionId == null ||
>>            deleteSessionId == null || listenIP == null ||
>>            behindFirewall == null)
>>        {
>>          String error = "<error>Bad Headers</error>";
>>          out.println(error);
>>          return;
>>        }
>>
>>        String xml = trafficCop.remove(urn, deleteSessionId,
>>sessionId,new URL(null,"pcp://"+listenIP, new Handler()),
>>                                        new
>>Boolean(behindFirewall).booleanValue(),0,0);
>>
>>        System.out.println(xml);
>>        out.println(xml);
>>      }
>>      else if (request.getRequestURI().endsWith("/update"))
>>      {
>>        response.setContentType(CONTENT_TYPE_XML);
>>        out.println("<?xml version=\"1.0\"?>");
>>
>>        String clientId = request.getHeader("PCP-Client-ID");
>>        String sessionId = request.getHeader("My-Session-ID");
>>        String listenIP = request.getHeader("Listen-IP");
>>        String behindFirewall = request.getHeader("Behind-Firewall");
>>
>>        String urn = request.getQueryString();
>>
>>        if (clientId == null || sessionId == null ||
>>            listenIP == null || behindFirewall == null)
>>        {
>>          String error = "<error>Bad Headers</error>";
>>          out.println(error);
>>          return;
>>        }
>>
>>        String xml = trafficCop.connectionUpdate(urn, sessionId,new
>>URL(null,"pcp://"+listenIP,new Handler()),
>>                                        new
>>Boolean(behindFirewall).booleanValue(),0,0);
>>
>>        System.out.println(xml);
>>        out.println(xml);
>>      }
>>    }
>>    catch (Exception e)
>>    {
>>      out.println("<error>"+e.getMessage()+"</error>");
>>      e.printStackTrace();
>>    }
>>  }
>>}
>>
>>-----Original Message-----
>>From: Tim Funk [mailto:funkman@joedog.org]
>>Sent: Monday, December 16, 2002 12:21 PM
>>To: Tomcat Users List
>>Subject: Re: Simultaneous request from same IP
>>
>>Can you post an example servlet (or the real code) that can reproduce
>>this? (No offense but ...) I really think there ios something with
>
> your
>
>>code.
>>
>>-Tim
>>
>>Chris Bick wrote:
>>
>>
>>>I've reproduced this problem with tomcat 3.2 and every version of 4.1
>>
>>up
>>
>>
>>>to 4.1.12
>>>
>>>I haven't gone any further than all headers being identical and the
>>>query string.  I thought maybe tomcat was just passing in the same
>>>reference, but the toString() value of the HttpServletRequest object
>>
>>are
>>
>>
>>>different.
>>>
>>>Let me know if anyone can reproduce this?(If you have the time...)
>>>
>>
>>
>>
>>--
>>To unsubscribe, e-mail:
>><mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>>For additional commands, e-mail:
>><mailto:tomcat-user-help@jakarta.apache.org>
>>
>>
>>--
>>To unsubscribe, e-mail:
>
> <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
>
>>For additional commands, e-mail:
>
> <mailto:tomcat-user-help@jakarta.apache.org>
>
>>
>>
>
>
> --
> To unsubscribe, e-mail:
> <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:tomcat-user-help@jakarta.apache.org>
>
>
> --
> To unsubscribe, e-mail:
<mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:tomcat-user-help@jakarta.apache.org>
>
>
>


--
To unsubscribe, e-mail:
<mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:tomcat-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:
<mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:tomcat-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message