brainjam
brainjam

Reputation: 19005

Google App Engine gives spurious content at beginning of page after quiescent period

I'm developing an app in Python for Google App Engine.

When I run the deployed app from appspot, it works fine unless I'm accessing it for the first time in over, say, 5 minutes. The problem is that if I haven't accessed the app for a while, the page renders with the message

Status: 200 OK Content-Type: text/html; charset=utf-8 Cache-Control: no-cache Expires: Fri, 01 Jan 1990 00:00:00 GMT Content-Length: 15493

prepended at the top. Usually that text is displayed for a second or two before the rest of the page is displayed.

If I check the server Logs, I see the info message

This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time.

The problem is easily corrected by refreshing the page. In this case, the page is delivered correctly, and works for subsequent refreshes. But if I wait 5 minutes, the problem comes back.

Any explanations, or suggestions on how to troubleshoot this? I've got a vague notion that when GAE "wakes up" after being inactive, there is an incorrect initialization going on. Or perhaps a header from a previous bout of activity is lingering in a buffer somewhere. But self.response.out seems to be empty when the request handler is invoked.

Upvotes: 1

Views: 114

Answers (1)

Nick Johnson
Nick Johnson

Reputation: 101149

Somewhere in your top level module code is something that uses Python print statements. Print outputs to standard out, which is what is returned as the response body; if it outputs a pair of newlines, the content before that is treated by the browser as the response header. The 'junk' you're seeing is the real response headers being produced by your webapp.

It's only happening on startup requests, because that's the only time the code in question gets executed.

Upvotes: 6

Related Questions