Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How guard against "orphaned" requests from multiple refreshes?  RSS feed

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
steve souza mentioned in another post here about how if a user hits refresh in a browser a bunch of times quickly, that can create "outstanding requests" and cause your web pages to hang. I've seen apps with this issue.

So my question: what do you have to do (in code or otherwise) to stop this issue?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37180
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan,
One common approach is to use a token that must be submitted with the request. The first request has a valid token and goes through. All other do not have a valid token and do not result in processing.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be easier said than done, but improving the response time so that the user isn't tempted to press the refresh button might be something to try.
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Dan,
One common approach is to use a token that must be submitted with the request. The first request has a valid token and goes through. All other do not have a valid token and do not result in processing.


Yes, but how do you get the requests and all the objects created with it to be "nulled" so there are no references to them anymore? Isn't that also part of the problem?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming we are talking about a servlet - the request and response objects will be managed by the container so I think you should just do a return from the service (or doGet or whatever) method and let the container handle it.
Bill
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by William Brogden:
Assuming we are talking about a servlet - the request and response objects will be managed by the container so I think you should just do a return from the service (or doGet or whatever) method and let the container handle it.
Bill



Right, but in order to "know" that you should just return without processing, how do you determine this is a dead request?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The same session object will be associated with all requests so you might try something like setting a "busy" flag or "pending request count" in the session. You will have to synchronize access to the session while setting or getting the busy flag since each request has the same session.
(Also make VERY sure that all exits from the servlet clear the busy flag)
Bill
[ November 25, 2005: Message edited by: William Brogden ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!