2012-05-17 60 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三個請求。 –

相關問題