2012-05-17 69 views
2

我在使用Firefox 12.0和GAE上的Python处理程序时遇到了一些奇怪的行为。在App Engine处理程序上接收来自Firefox 12.0的多个HTTP请求

当我在Firefox中请求这个处理程序时,它会运行3次 - 但只有当它返回一个GIF时。

我目前正在通过设置基于处理程序的查询字符串的memcache条目来绕过它。我希望这会防止相同信息的重复db.put()。

这里有一个工作URL:http://test-o-tron.appspot.com - 请注意,您可以更改这些查询字符串参数:

  • 格式( “GIF” 或 “HTML”)
  • 黑客( “真” 或 “假”)
  • mkey_suffix(串在内存缓存键用于容易复位计数器)

下面的代码:

from google.appengine.api import urlfetch, memcache 
from google.appengine.ext import db 
import webapp2, random 

class MainHandler(webapp2.RequestHandler): 
    def get(self): 

     #If user doesn't have an mkey_suffix, make one 
     if self.request.get("mkey_suffix") == "": 
      self.redirect("/?format=gif&hack=false&mkey_suffix=" + 
          self.request.remote_addr + 
          "." + str(random.randint(0, 1000))) 


     OUTPUT_GIF = self.request.get("format") == "gif" 
     USE_HACK = self.request.get("hack") == "true" 

     #Memcache keys 
     mkey_suffix = self.request.get("mkey_suffix") 
     mkey_log = "log" + mkey_suffix 
     mkey_hack = "hack" + mkey_suffix 

     #Count the number of requests using memcache 
     if memcache.get(mkey_log) is None: 
      memcache.set(mkey_log, 0, 60) 
     counter = memcache.get(mkey_log) 

     #Hack!! Only handle a given request ONCE every second 
     if not USE_HACK or memcache.get(mkey_hack) is None: 
      memcache.set(mkey_hack, True, time=1) 

      #Show I'm not crazy 
      counter += 1 
      memcache.set(mkey_log, counter, 60) 

     #Return counter value 
     if OUTPUT_GIF: 

      self.response.headers["Content-Type"] = "image/gif" 
      img_url = "http://placehold.it/{counter}x{counter}" 
      img_url = img_url.format(counter=str(400 + counter)) 
      img_data = urlfetch.Fetch(img_url).content 
      content = db.Blob(img_data) 


     else: 

      #Output HTML 
      self.response.headers["Content-Type"] = "text/html" 
      content = "Counter == " + str(counter) 

     self.response.out.write(content) 


app = webapp2.WSGIApplication([('/', MainHandler)], debug=True) 

回答

1

的AppEngine上小组报告了以下错误:

Investigating reports of a Google App Engine issue in which requests are being executed multiple times on June 13, 2013

We are investigating reports of an issue with Google App Engine in which a request can get executed multiple times. This shows up in Admin Console logs as a request to a frontend that runs for longer than a minute. We will provide more information shortly.

6月14日,他们发表了如下更新:

We have determined the root cause, and implemented a fix, which will be rolling out over the next few days. You should expect little to no ongoing impact to running applications. We will provide a more detailed analysis of this issue once we have completed our internal investigation.

+0

“2013年6月17日美国/太平洋时间晚上10:38解决了多次执行Google App Engine请求的问题。我们对给您带来的不便表示歉意,并感谢您的耐心和持续的支持。请放心,系统可靠性是谷歌的首要任务,我们正在不断改进,以使我们的系统更好,一旦我们完成了内部调查,我们将对此事件进行更详细的分析。“ –

1

您可以从您的请求日志中获得同等信息,而无需诉诸这种破解。

您是否打算让您的应用服务动态GIF?如果您的GIF是静态的,并且您在app.yaml中声明它们,则处理程序将完全绕过。可能仍然存在某种类型的Firefox呃逆,但您的应用程序的负载不会反映出来。

https://developers.google.com/appengine/docs/python/gettingstarted/staticfiles

+0

这是一个跟踪像素,所以我需要解析结附的查询字符串到它。 – marclar

0

什么是你的问题?我敢打赌,这是某种Firefox行为,它正在请求图标或尝试向前看或什么。

+0

啊 - 我认为这很明显,但问题是:“我怎样才能解决这个问题而不诉诸于破解?” – marclar

+0

你最好先理解为什么FF seNds三个请求。 –

相关问题