http HandleFunc being called multiple times per request

378 views
Skip to first unread message

Nick S

unread,
Apr 15, 2012, 1:17:12 PM4/15/12
to google-ap...@googlegroups.com

func init() {

http.HandleFunc("/", handler)

}

The handler func isn't returning, and the logs show that the handler is being executed multiple times. 

Just now it ran for almost (I pauses the queue) 10 minutes, just looping..There is no error messages in the logs.

Any ideas what could cause this?

Ps.

The actual code being run is quote memory intensive, I had to switch to a F2 instance because of the memory limit. It might have to do with memory issues, maybe the Go runtime re-executes the request under some conditions?

The handler seems to reset partially though execution...

There should be a log for each of N (lets say 100) inputs.  The logs shown are from 1 to 20, repeating, 1 to 20, 1 to 20,... 

David Symonds

unread,
Apr 15, 2012, 6:24:54 PM4/15/12
to Nick S, google-ap...@googlegroups.com
It's not clear to me what the problem is. Can you describe it more
precisely? What's your handler func? What do you see in the admin
console logs when you visit your app?


Dave.

Message has been deleted

Nick S

unread,
Apr 15, 2012, 10:36:02 PM4/15/12
to google-ap...@googlegroups.com, Nick S

David Symonds

unread,
Apr 15, 2012, 11:22:47 PM4/15/12
to Nick S, google-ap...@googlegroups.com
You still haven't shown us what your app's code is for the handler function.

Nick S

unread,
Apr 16, 2012, 10:50:47 AM4/16/12
to google-ap...@googlegroups.com, Nick S
The handler reads a list of documents from the datastore, indexes them in memory, does some processing, and saves the results to the datastore.  I can't post the code, it is the entire Go portion of the app. I will try to create a minimal test app that exhibits the same behavior.

Are there any known situations where a handler will be executed multiple times?  

Brad Fitzpatrick

unread,
Apr 16, 2012, 11:19:41 AM4/16/12
to Nick S, google-ap...@googlegroups.com
On Mon, Apr 16, 2012 at 7:50 AM, Nick S <nix...@gmail.com> wrote:
...
Are there any known situations where a handler will be executed multiple times?  

It's not /favicon.ico is it?
 

Peter Thrun

unread,
Apr 16, 2012, 11:23:16 AM4/16/12
to google-ap...@googlegroups.com, Nick S
Is it possible that the handler does not handle simultaneous requests?  Because the handler is registered for "/", requesting "/" in the browser will typically result in two quick requests to the handler. One request is for / and the other is for favicon.ico.

Nick S

unread,
Apr 16, 2012, 1:07:00 PM4/16/12
to google-ap...@googlegroups.com, Nick S
I do see the request for favicon.ico in the logs,  the "/" handler expects a request parameter which isn't present, so the request for favicon returns immediately with status 200.

The Dashboard shows a sustained request rate of 0.4rps while I was testing.  Could I be returning something that tells the browser to re-request.  I was checking the chrome network monitor at that time, and it only showed one pending request (well beyond the 30 second request limit though...).
p4rps.png

Nick S

unread,
Apr 16, 2012, 1:10:11 PM4/16/12
to google-ap...@googlegroups.com, Nick S
I just want to clarify that I was making a single request about every few minutes, so the 0.4RPS is unexpected.

Nick S

unread,
Apr 16, 2012, 1:32:07 PM4/16/12
to google-ap...@googlegroups.com, Nick S
I've added a favicon and updated the yaml accordingly. I also changed the the handler to handle "abc" not "/".

I switched back to a F1 instance and it seems to be working...THANKS!

I'm still unsure why the handler was being called multiple times in one request.


On Monday, April 16, 2012 11:23:16 AM UTC-4, Peter Thrun wrote:

Peter Thrun

unread,
Apr 16, 2012, 2:05:01 PM4/16/12
to google-ap...@googlegroups.com, Nick S
I've added a favicon and updated the yaml accordingly. I also changed the the handler to handle "abc" not "/".

With this change, you are now testing with one concurrent request to the handler.  Is it possible that the handler code is not thread-safe and the multiple concurrent requests are corrupting memory?

Nick S

unread,
Apr 16, 2012, 2:12:39 PM4/16/12
to google-ap...@googlegroups.com, Nick S
I'm not using any top level variables, so I think it would be thread-safe.
Reply all
Reply to author
Forward
0 new messages