That's the way I understand it. I guess TrafficCop could be doing something screwy, but I'm not sure what. (We note that the "header-read" code in the servlet (which presumably uses some kind of collection-lookup) could be running at the same time as TrafficCop is doing something, because a lock won't be attempted until you reach the add() method. Still, that seems a little obscure given that you say you can reproduce this every run.)
I just had a thought. Are you sure that your code that generates the requests isn't operating in an "unthreadsafe" fashion and sending duplicate requests? Mike. ----- Original Message ----- From: "Chris Bick" <[EMAIL PROTECTED]> To: "Tomcat Users List" <[EMAIL PROTECTED]> Sent: Monday, December 16, 2002 6:25 PM 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:[EMAIL PROTECTED]] 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:[EMAIL PROTECTED]] > 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:[EMAIL PROTECTED]] >>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:[EMAIL PROTECTED]> >>For additional commands, e-mail: >><mailto:[EMAIL PROTECTED]> >> >> >>-- >>To unsubscribe, e-mail: > > <mailto:[EMAIL PROTECTED]> > >>For additional commands, e-mail: > > <mailto:[EMAIL PROTECTED]> > >> >> > > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > > > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
