-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
functions called from browser execute twice #33
Comments
Very interesting. I can confirm that I'm also encountering this issue. @swalkowski any idea what might be causing this? |
OK so we think this is happening because browser requests also send a request for a favicon. This means that hitting the function in the browser results in two invocations of the function. I think we can fix this by changing our logic to only invoke the function in response to requests on Thanks for the report. |
Looks like the fix would be: |
I've created a PR to fix this. |
Fixed in |
Why have you reverted this without any explanation? 1.3.2 still executes twice. |
I reverted this because it was not compatible with GCF. Requests to a deployed function to GCF would return an error. We are working on solving this issue. |
Looks like internal bug is b/133880441 |
Thank you for clarification, Grant. For development as a workaround I use Express and bind my functions to URIs there. In index.js I check if production Cloud Functions environment is not available and then configure Express itself with all project functions as a main function. This approach makes possible to run several functions simultaneously and the problem with double execution disappears. |
I'm glad I stumbled on this thread. @stew-r is correct, when accessed by a browser, it requests an additional payload for favicon.ico. I'm just putting this up for future me and people get annoyed by this extra invocation. You can wrap your statements via: if (req.originalUrl !== "/favicon.ico") {
console.log("running HelloWorld");
} Or just use express as @dobromyslov suggest and use a middleware that ignores the favicon. function noFavicon(req, res, next) {
req.originalUrl === "/favicon.ico" ? res.status(204).json({}) : next();
}
app.use(noFavicon) or just add a new route app.get("/favicon.ico", (req, res) => res.status(204).json({})); |
👍 When running
the logs show
Didn't realize that if you just run that, it will also request the fav icon. but explicitly setting the path as the function in your call it will avoid the favicon call. |
Hello, I have the same problem, but I do not understand the answers speaking the link with favicon: in the second call, I find in "req.url" the same path as in the first call. Does anyone know how to block this in Chrome? |
Im running into the same behavior that @Didier68 is. Chome and apparently Edge are requesting the same route 2 times in a row. The 2nd time, the request has a 'Referer' header that is the value of the route itself. So it looks like its just sending 2 requests one right after the other. |
Although curl will only call the function once.
Chrome load or refresh calls the function twice.
A bit confusing when debugging something more complex than HelloWorld.
Very easy to see:
Is there a way to stop this?
The text was updated successfully, but these errors were encountered: