I'm having an intermittent issue with a map on the following page

http://www.relate.org.uk/find-your-nearest-relate

I get a js error

Failed to load resource: the server responded with a status of 403 (OK)

If I clear the cache the map works again, the site is using varnish and the map does work when logged in so it's almost definitely a caching issue.

Any ideas what is actually happening here?

Cheers Dan

Comments

danharper created an issue. See original summary.

RdeBoer’s picture

Hi Dan,

What can kill Varnish is if one of the Drupal modules uses $_SESSION.

IPGV&M only uses the $_SESSION to store the current user location, but if you don't use it you should be fine as far as IPGV&M is concerned. Or if you DO use the current user location, then also enable the module Session Cache API.

However another Drupal module may use $_SESSION (to store data snippets for anonymous users).

Background; http://flink.com.au/tips-tricks/erased-memories-cracked-varnish
Module: https://www.drupal.org/project/session_cache (only effective for modules that use its API, like IPGV&M)

Rik

danharper’s picture

I did have session cache api installed but it was set to use the users cookie and expire it after 7 days, this module was used as part of some old functionality so I have turned it off although it shouldn't change the behaviour of the site only make an API available where it is needed.

I have turned off the session cache api and the map works but this is more likely to do with the site cache being cleared so I will monitor it.

Cheers Dan

roman_pro’s picture

I'm having the same problem - I'm also using Varnish on Pantheon.
Did you have any luck?

danharper’s picture

No, I haven't managed to solve this yet.

I will be looking into it this week though.

Dan

roman_pro’s picture

I'm testing with hardcoded API key...

RdeBoer’s picture

Title: Failed to load resource 403 » IPGV&M + arnish results in "Failed to load resource: the server responded with a status of 403 (OK)"
RdeBoer’s picture

Title: IPGV&M + arnish results in "Failed to load resource: the server responded with a status of 403 (OK)" » IPGV&M + Varnish results in "Failed to load resource: the server responded with a status of 403 (OK)"
andyg8’s picture

I'm having the same problem. The url is of the form:
https://maps.googleapis.com/maps/api/js/ViewportInfoService.GetViewportInfo?1m6&1m2&... many numbers ... 2&4sen-US&5e0&6sm% ... more numbers .... &callback=_xdc_._55iiyc&token=more numbers...

The error in console is: Failed to load resource: the server responded with a status of 403 (OK)

The error displayed when I open this URL on its own tab is:
The Google Maps JavaScript API must be downloaded directly from Google's servers. Learn more: https://developers.google.com/maps/documentation/javascript/tutorial#Loa...

This has only started happening in the last couple of days, and I haven't updated anything in Drupal.

Thanks for your ideas!

RdeBoer’s picture

All I can say: No idea. Sorry.

The latest trouble reported by @andy8 seems to introduce new symptoms.

Previous issues with Varnish were around the fact that a module in your setup (not necessarily IPGV&M) may be using PHP's $_SESSION, most likely for anonymous users.

If you ARE using the "Set my location" block to locate a visitor, then IPGV&M will use $_SESSION by default. But you can circumvent that by enabling Session Cache API, https://www.drupal.org/project/session_cache, and then on its configuration page select, say File as the storage module and IP address as the key.

However, as I said, symptoms this time seem a little different.

Rik

jimmynash’s picture

I've been seeing this same issue on occasion with a new site that was just launched on Pantheon.

I had two thoughts, there is a patch here that just made it into 1.28
https://www.drupal.org/node/2564865

and maybe it could be an issue with the version of the maps api being loaded?

In Google's versioning documentation if the v parameter isn't specified, it will load the most current version which right now is 3.22
I had an issue on another project where setting the version to the current release version (3.21) fixed up the problem. To do that I just had to specify v=3 when calling the maps api js.

I think right now I'm going to just patch with the patch in https://www.drupal.org/node/2564865 and see if that helps.

RdeBoer’s picture

Thank @jimmynash -- look forward to your findings.
Rik

jimmynash’s picture

I checked again this morning and while I didn't get an error from google, I did get a "set map center and zoom first" error.

I think this is due to my settings and the map not having a default on load. I followed this thread https://www.drupal.org/node/2334609 but I'm not sure that the solution there applies to me or not.

My set up is a little strange and if what I'm doing isn't right or there is a better way I'd appreciate some input.

I have the map page set up with the "Set Location" block on the page but hidden. The map is set to center on the visitors location.
I have a custom module running hook_views_pre_execute. For the map view, it uses the function ip_geoloc_get_visitor_location() and checks to see if there is relevant data in there like the locality.

If it has no usable location data, I output some js that triggers the "Find Me" functionality of the Set Location block. This prompts the user and everything works great.

I did see a notice in the logs saying:
"Notice: Undefined index: city in ip_geoloc_store_location()" at about the same time as my load of the map.

Would that be caused by the module not having any stored locations to work off of?

Again, when clearing my caches everything begins running as normal.

I don't want to muddy the issue with my implementation but I still think there is a cache thing going on.
FWIW I have tried using the session_cache api module and it was causing my set up to loop prompting for locations.

I'll keep looking into this. It may just be my setup.

RdeBoer’s picture

@jimmynash

"Again, when clearing my caches everything begins running as normal."

Hmm... what's going on...

Yes your setup convolutes the issue somewhat....

Are you using IPGV&M's Google API or the Leaflet API ? The Leaflet API works best with the "Set my location" block. You can still show Google maps, just using the Leaflet API.

Yes, the notice means it is trying to store on the db a visitor location that isn't complete. Do you need to store visitor locations? If not, then you can switch it off and avoid that error.

Rik

andyg8’s picture

Hmm... I realise now I might have posted my issue in the wrong place; we don't use Varnish - we just have a straight usage case of showing a map from a lattitude and longitude field in Views. Nevertheless, it may be that our issue is from the same cause, reading the points above. Please feel free to direct me elsewhere.

We've found the map appearing and disappearing over the last week. Just then i tried clearing caches very thoroughly and that made the map reappear...

I tried just clearing the Views, registry and module caches but that made no difference. But drush cc all and then emptying all the cache tables in the db did the trick.

Is there any information I could give that might help get to the bottom of this?

jimmynash’s picture

@RdeBoer

I am using the Leaflet API and Leaflet More Maps to use the google map instead of OSM.

Checking in on it this morning. When I hit the map directly, the map doesn't load and leaflet.js throws and error in the console saying "Error: Set map center and zoom first.".

Right now in the Format Settings for the Map View I have the No Locations behavior set to "visitor". Maybe if I set that to a specific latlon I might not have this issue anymore?
So if there is no stored location to be used for "visitor" it throws that error?

I think what is going on at this point is that the IPGV&M behavior is normal. It has no locations to work off of so it suppresses the map. If the user clicks the Find me button at that point it refreshes and work great again.

I suppose I might be able to use the No Results Behavior to do something useful in this case too. I just have to see if I can replicate this behavior on my dev.

Before I ramble too much, the patch that I applied for the external javascript fix from earlier seems to have cleared my issue with loading the google maps api. I think now my issue is just with how I have IPGV&M configured. I'll play with some settings and see if I can't resolve that and post back. But for now I don't think I have a cache issue anymore now that the js is being handled correctly.

Thanks for your help!

jimmynash’s picture

So after a little monkeying around, I found I could replicate this by clearing the ip_geoloc table and loading my map.

Since the settings for no results were set to "visitor" and there was nothing for it to use, it would suppress the map and throw the js error for setting the center and zoom.

Since I was outputting another script to click the "Find Me" button and trigger browser geolocation, my script wouldn't run because of that error.

My solution for now was to set the no results setting to a lat lon. This allows the map to load and my js to prompt the user for their location.

I believe that the external js patch is working and I am not experiencing any more cache issues with this.

jimmynash’s picture

Apparently this is still happening. After a few days I start seeing the maps.google.com/maps/api/js/AuthenticationService.Authenticate call in the console return a 403 forbidden.

I found this that might be relevant.
http://stackoverflow.com/questions/10719319/after-months-of-100-stabilit...
RequestReduce is not in play here.

Since this only comes up after a longer period of time it is difficult to determine what is going on.

I've added a cache=>false to the drupal_add_js calls in the ip_geoloc_api.inc file to see if that makes any difference and will check in with it later.
I'm not certain that IPGV&M is the issue yet or if it might be geophp or the geocoder module.

I apologize if I'm muddying up this issue.

RdeBoer’s picture

Hi @Jimmynash
No i don't think you are muddying up the issue. That stackoverflow link seems highly relevant.
It does seem to confirm the problem is around stuff getting cached and Google Maps balking at that.
Look forward to hearing how you're going with that cache=>false option.
Rik

jimmynash’s picture

Well, again after the weekend, the Authentication Service call was bad.
Clearing the caches in Drupal fixed the issue.

I don't think the cache->false made any difference and based on what I see in the documentation for drupal_add_js that is only applied if the type is file.

I'm going to try specifying a param on the call to the maps api to specify the version.
According to the maps api documentation, not specifying a version will give the latest experimental which is 3.22
I'm going to specify v=3 which should give me back 3.21 at this point.

https://developers.google.com/maps/documentation/javascript/versions

jimmynash’s picture

I decided not to use the cache option on the IPVGM drupal_add_js calls since it wasn't making any difference.
External should be good enough for breaking aggregation i think.

I did notice however that when the issue with the 403 forbidden call came up again on my dev environment, that in the source, the only references to maps.googleapis.com were in the Jquery extend line that drupal adds.

I found this github issue on another project in my googling.
https://github.com/OpenTreeMap/otm-core/issues/198

It mentions having the script for google maps in it's own script tag.
This was not happening for me.

IPGVM looks to see if the maps js is in the javascript array before adding it.

There are other modules installed in my site that also try to add the main maps js.
The geofield module is one of them that looks to be the closest. It adds the js in a render array with the external parameter set.
External should stop it from aggregating and caching.

When looking at the js files being added I could see the maps js loaded but it's parameters were type => file, preprocess => true and cache => true.
Hooking the js files as below let me fix that and now the google maps js is in it's own script tag.

function mymodule_js_alter(&$javascript) {
  foreach ($javascript as $key => $value) {
    if(strpos($key, 'maps.googleapis.com/maps/api/js') !== FALSE){
      if(is_array($javascript[$key])){
        $javascript[$key]['cache'] = FALSE;
        $javascript[$key]['type'] = 'external';
        $javascript[$key]['preprocess'] = FALSE;
      }
    }
  }
}

It has been three days and I have not seen the issue crop up again.

I don't think IPGVM is at fault here for the issue. But I'm not sure why the js was being aggregated and cached since it looked to be added correctly from the other modules.

So far, so good.

RdeBoer’s picture

Hi @jimmynash,

Looks like you got to the bottom and solved it!

So at the end of all this, the solution appears to be to put the "script for google maps in its own script tag".

You've accomplished this through your own mini-module. Well done!

Do you see any opportunities for something that can be done in existing modules, including IPGV&M, to make this work out-of-the-box for everyone, without us having to write a mini-module?

What would you recommend?

Rik

jimmynash’s picture

@RdeBoer

I'm not really sure what to recommend at this point.

IPGV&M checks to see that the maps api is in the js array before trying to add it which is good. Might be more than other modules do.

Of the other modules that I have installed that add it, they use the external parameter on their calls to drupal_add_js.
From what I read in the documentation for that function, having external specified for the type should be enough to keep that js from being aggregated.

I don't think it should be up to IPGV&M to try and fix the aggregation if it isn't being forced off.
I also don't really see any reason to think that other modules are adding the maps api incorrectly.

This is my list of installed and enabled modules that have some "maps.googleapis.com" in them:

grep -R "maps.googleapis.com" .
./webform_gmap_location/webform_gmap_location.components.inc: $g_link = 'http://maps.googleapis.com/maps/api/js?libraries=places&sensor=true&lang...';
./webform_gmap_location/webform_gmap_location.components.inc: $g_link = 'http://maps.googleapis.com/maps/api/js?libraries=places&sensor=true&lang...';
./geocoder/plugins/geocoder_handler/google.inc: $url = url("https://maps.googleapis.com/maps/api/geocode/json", array(
./geofield/modules/geofield_map/includes/geofield_map_plugin_style_map.inc: drupal_add_js('//maps.googleapis.com/maps/api/js?sensor=false', 'external');
./geofield/modules/geofield_map/geofield_map.module: '//maps.googleapis.com/maps/api/js?sensor=false' => array('type' => 'external'),
./ip_geoloc/ip_geoloc_api.inc:define('IP_GEOLOC_GOOGLE_MAPS', 'https://maps.googleapis.com/maps/api/js?sensor=false');
./ip_geoloc/ip_geoloc_api.inc:define('IP_GEOLOC_GOOGLE_MAPS_GPS', 'https://maps.googleapis.com/maps/api/js?sensor=true');
./ip_geoloc/ip_geoloc_api.inc:define('IP_GEOLOC_GOOGLE_MAPS_SERVER', 'https://maps.googleapis.com/maps/api/geocode/json?sensor=false');
./ip_geoloc/ip_geoloc_api.inc: * http://maps.googleapis.com/maps/api/geocode/json?sensor=false&latlng=-37...

Webform Gmap adds it with the external parameter.
geocoder doesn't seem to add the api, it looks to just use the json returned from drupal_http_request
geofield - geofield_map seems to add it with the external parameter.

Would it even make sense for IPVG&M to implement hook_js_alter to ensure that the maps api isn't being cached? Maybe as a configuration option?

danharper’s picture

@jimmynash, thanks for the work on this we implemented your suggestion on Monday and it seems to have fixed the issue.

jimmynash’s picture

@danharper

Fantastic! Glad it helped you out.